diff --git a/build/src/mongoose.c b/build/src/mongoose.c index fcb293617fb4bed4c4e474cd9b57a9ee044c2d90..cdc9ae18d7da569a1c00c075354e9e6c461ea52c 100644 --- a/build/src/mongoose.c +++ b/build/src/mongoose.c @@ -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); } else { // Request is valid. Set content_len attribute by parsing Content-Length - // If Content-Length is absent, instruct mg_read() to read from the socket - // until socket is closed. + // If Content-Length is absent, set content_len to 0 if request is GET, + // 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; + if (!mg_strcasecmp(conn->request_info.request_method, "GET")) { + conn->content_len = 0; + } if ((cl = get_header(&conn->request_info, "Content-Length")) != NULL) { conn->content_len = strtoll(cl, NULL, 10); } diff --git a/mongoose.c b/mongoose.c index 35ce41a96ac25ef19fa51214ea3c908a4660bdcd..02fb9f8e2d5b5416887f56cacda426de198933bb 100644 --- a/mongoose.c +++ b/mongoose.c @@ -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); } else { // Request is valid. Set content_len attribute by parsing Content-Length - // By default, in the absence of Content-Length, instruct mg_read() - // to read from the socket until the socket is closed. + // If Content-Length is absent, set content_len to 0 if request is GET, + // 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; + if (!mg_strcasecmp(conn->request_info.request_method, "GET")) { + conn->content_len = 0; + } if ((cl = get_header(&conn->request_info, "Content-Length")) != NULL) { conn->content_len = strtoll(cl, NULL, 10); }