mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 21:53:12 +00:00
Allow POST requests with no Content-Length
This commit is contained in:
parent
af2d32c25b
commit
65bc309999
@ -1305,11 +1305,15 @@ static int http_request_start_body(struct http_request *r)
|
|||||||
assert(r->version_major != 0);
|
assert(r->version_major != 0);
|
||||||
assert(r->parsed <= r->end);
|
assert(r->parsed <= r->end);
|
||||||
|
|
||||||
|
// No header should probably be treated the same as no content
|
||||||
|
// Though some server implementations disagree
|
||||||
|
// http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0275.html
|
||||||
|
if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN && !r->request_header.chunked)
|
||||||
|
r->request_header.content_length = 0;
|
||||||
|
|
||||||
if (r->verb == HTTP_VERB_GET) {
|
if (r->verb == HTTP_VERB_GET) {
|
||||||
// TODO: Implement HEAD requests (only send response header, not body)
|
// TODO: Implement HEAD requests (only send response header, not body)
|
||||||
if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN)
|
if (r->request_header.chunked || r->request_header.content_length != 0) {
|
||||||
r->request_header.content_length = 0;
|
|
||||||
if (r->request_header.content_length != 0) {
|
|
||||||
IDEBUGF(r->debug, "Malformed HTTP %s request: non-zero Content-Length not allowed", r->verb);
|
IDEBUGF(r->debug, "Malformed HTTP %s request: non-zero Content-Length not allowed", r->verb);
|
||||||
return 400;
|
return 400;
|
||||||
}
|
}
|
||||||
@ -1324,9 +1328,6 @@ static int http_request_start_body(struct http_request *r)
|
|||||||
r->decoder = http_request_decode_chunks;
|
r->decoder = http_request_decode_chunks;
|
||||||
r->end = r->decode_ptr = r->parsed;
|
r->end = r->decode_ptr = r->parsed;
|
||||||
r->chunk_state = CHUNK_SIZE;
|
r->chunk_state = CHUNK_SIZE;
|
||||||
}else if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN) {
|
|
||||||
IDEBUGF(r->debug, "Malformed HTTP %s request: missing Content-Length or Transfer-Encoding: chunked header", r->verb);
|
|
||||||
return 411; // Length Required
|
|
||||||
}
|
}
|
||||||
if (r->request_header.content_length == 0) {
|
if (r->request_header.content_length == 0) {
|
||||||
r->parser = NULL;
|
r->parser = NULL;
|
||||||
@ -1376,7 +1377,7 @@ static int http_request_start_body(struct http_request *r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_run_out(r))
|
if (r->request_content_remaining && _run_out(r))
|
||||||
return 100;
|
return 100;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -49,20 +49,6 @@ public class KeyringCommon
|
|||||||
public KeyringIdentity identity;
|
public KeyringIdentity identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dumpStatus(Status status, PrintStream out)
|
|
||||||
{
|
|
||||||
out.println("input_stream=" + status.input_stream);
|
|
||||||
out.println("http_status_code=" + status.http_status_code);
|
|
||||||
out.println("http_status_message=" + status.http_status_message);
|
|
||||||
if (status.identity == null) {
|
|
||||||
out.println("identity=null");
|
|
||||||
} else {
|
|
||||||
out.println("identity.subscriber=" + status.identity.subscriber);
|
|
||||||
out.println("identity.did=" + status.identity.did);
|
|
||||||
out.println("identity.name=" + status.identity.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static Status receiveResponse(HttpURLConnection conn, int expected_response_code) throws IOException, ServalDInterfaceException
|
protected static Status receiveResponse(HttpURLConnection conn, int expected_response_code) throws IOException, ServalDInterfaceException
|
||||||
{
|
{
|
||||||
int[] expected_response_codes = { expected_response_code };
|
int[] expected_response_codes = { expected_response_code };
|
||||||
@ -176,13 +162,6 @@ public class KeyringCommon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dumpHeaders(HttpURLConnection conn, PrintStream out)
|
|
||||||
{
|
|
||||||
for (Map.Entry<String,List<String>> e: conn.getHeaderFields().entrySet())
|
|
||||||
for (String v: e.getValue())
|
|
||||||
out.println("received header " + e.getKey() + ": " + v);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String quoteString(String unquoted)
|
private static String quoteString(String unquoted)
|
||||||
{
|
{
|
||||||
if (unquoted == null)
|
if (unquoted == null)
|
||||||
@ -214,7 +193,6 @@ public class KeyringCommon
|
|||||||
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_OK);
|
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_OK);
|
||||||
try {
|
try {
|
||||||
decodeRestfulStatus(status);
|
decodeRestfulStatus(status);
|
||||||
dumpStatus(status, System.err);
|
|
||||||
if (status.identity == null)
|
if (status.identity == null)
|
||||||
throw new ServalDInterfaceException("invalid JSON response; missing identity");
|
throw new ServalDInterfaceException("invalid JSON response; missing identity");
|
||||||
|
|
||||||
@ -241,7 +219,6 @@ public class KeyringCommon
|
|||||||
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_CREATED);
|
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_CREATED);
|
||||||
try {
|
try {
|
||||||
decodeRestfulStatus(status);
|
decodeRestfulStatus(status);
|
||||||
dumpStatus(status, System.err);
|
|
||||||
if (status.identity == null)
|
if (status.identity == null)
|
||||||
throw new ServalDInterfaceException("invalid JSON response; missing identity");
|
throw new ServalDInterfaceException("invalid JSON response; missing identity");
|
||||||
return status.identity;
|
return status.identity;
|
||||||
@ -263,7 +240,6 @@ public class KeyringCommon
|
|||||||
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_OK);
|
Status status = receiveRestfulResponse(conn, HttpURLConnection.HTTP_OK);
|
||||||
try {
|
try {
|
||||||
decodeRestfulStatus(status);
|
decodeRestfulStatus(status);
|
||||||
dumpStatus(status, System.err);
|
|
||||||
if (status.identity == null)
|
if (status.identity == null)
|
||||||
throw new ServalDInterfaceException("invalid JSON response; missing identity");
|
throw new ServalDInterfaceException("invalid JSON response; missing identity");
|
||||||
return status.identity;
|
return status.identity;
|
||||||
|
Loading…
Reference in New Issue
Block a user