mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-13 17:00:19 +00:00
Set content_len to 0 for GET requests without Content-Length header.
This commit is contained in:
1 parent
5153eebc9b
commit
87d841d81b
2 files changed
+18
-4
No files matched your search
@@ -3643,9 +3643,16 @@ static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len) {
|
|||||||
snprintf(ebuf, ebuf_len, "Bad request: [%.*s]", conn->data_len, conn->buf);
|
snprintf(ebuf, ebuf_len, "Bad request: [%.*s]", conn->data_len, conn->buf);
|
||||||
} else {
|
} else {
|
||||||
// Request is valid. Set content_len attribute by parsing Content-Length
|
// Request is valid. Set content_len attribute by parsing Content-Length
|
||||||
// If Content-Length is absent, instruct mg_read() to read from the socket
|
// If Content-Length is absent, set content_len to 0 if request is GET,
|
||||||
// until socket is closed.
|
// and set it to INT64_MAX otherwise. Setting to INT64_MAX instructs
|
||||||
|
// mg_read() to read from the socket until socket is closed.
|
||||||
|
// The reason for treating GET and POST/PUT differently is that libraries
|
||||||
|
// like jquery do not set Content-Length in GET requests, and we don't
|
||||||
|
// want mg_read() to hang waiting until socket is timed out.
|
||||||
conn->content_len = INT64_MAX;
|
conn->content_len = INT64_MAX;
|
||||||
|
if (!mg_strcasecmp(conn->request_info.request_method, "GET")) {
|
||||||
|
conn->content_len = 0;
|
||||||
|
}
|
||||||
if ((cl = get_header(&conn->request_info, "Content-Length")) != NULL) {
|
if ((cl = get_header(&conn->request_info, "Content-Length")) != NULL) {
|
||||||
conn->content_len = strtoll(cl, NULL, 10);
|
conn->content_len = strtoll(cl, NULL, 10);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-2
@@ -4954,9 +4954,16 @@ static int getreq(struct mg_connection *conn, char *ebuf, size_t ebuf_len) {
|
|||||||
snprintf(ebuf, ebuf_len, "Bad request: [%.*s]", conn->data_len, conn->buf);
|
snprintf(ebuf, ebuf_len, "Bad request: [%.*s]", conn->data_len, conn->buf);
|
||||||
} else {
|
} else {
|
||||||
// Request is valid. Set content_len attribute by parsing Content-Length
|
// Request is valid. Set content_len attribute by parsing Content-Length
|
||||||
// By default, in the absence of Content-Length, instruct mg_read()
|
// If Content-Length is absent, set content_len to 0 if request is GET,
|
||||||
// to read from the socket until the socket is closed.
|
// and set it to INT64_MAX otherwise. Setting to INT64_MAX instructs
|
||||||
|
// mg_read() to read from the socket until socket is closed.
|
||||||
|
// The reason for treating GET and POST/PUT differently is that libraries
|
||||||
|
// like jquery do not set Content-Length in GET requests, and we don't
|
||||||
|
// want mg_read() to hang waiting until socket is timed out.
|
||||||
conn->content_len = INT64_MAX;
|
conn->content_len = INT64_MAX;
|
||||||
|
if (!mg_strcasecmp(conn->request_info.request_method, "GET")) {
|
||||||
|
conn->content_len = 0;
|
||||||
|
}
|
||||||
if ((cl = get_header(&conn->request_info, "Content-Length")) != NULL) {
|
if ((cl = get_header(&conn->request_info, "Content-Length")) != NULL) {
|
||||||
conn->content_len = strtoll(cl, NULL, 10);
|
conn->content_len = strtoll(cl, NULL, 10);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user