diff --git a/mongoose.c b/mongoose.c index 188d572f..6059c93b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4785,8 +4785,9 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) { // contain a Content-length header (unless the body length is 0, in // which case it can be omitted). Other requests can also contain a // body, but their content has no defined semantics (RFC 7231) + // It is a non-chunked request, so the offset (ofs) is updated after + // exiting this branch. if (hm.body.len != 0) require_content_len = true; - ofs += (size_t) n; // this request has been processed } else if (is_response) { // HTTP spec 7.2 Entity body: All other responses must include a body // or Content-Length header field defined with a value of 0. diff --git a/src/http.c b/src/http.c index bab0d8bd..d3b23c78 100644 --- a/src/http.c +++ b/src/http.c @@ -1183,8 +1183,9 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) { // contain a Content-length header (unless the body length is 0, in // which case it can be omitted). Other requests can also contain a // body, but their content has no defined semantics (RFC 7231) + // It is a non-chunked request, so the offset (ofs) is updated after + // exiting this branch. if (hm.body.len != 0) require_content_len = true; - ofs += (size_t) n; // this request has been processed } else if (is_response) { // HTTP spec 7.2 Entity body: All other responses must include a body // or Content-Length header field defined with a value of 0. diff --git a/test/unit_test.c b/test/unit_test.c index 713001ec..2dc56c6c 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -1758,6 +1758,14 @@ static void test_http_pipeline(void) { for (i = 0; i < 20; i++) mg_mgr_poll(&mgr, 1); ASSERT(ok == 1); ASSERT(ok2 == 1); + // A bodyless POST must not consume the following pipelined request + ok = ok2 = 0; + c = mg_http_connect(&mgr, url, f6, (void *) &ok2); + mg_printf(c, "POST /x HTTP/1.1\r\nHost: h\r\n\r\n" + "GET /next HTTP/1.1\r\nHost: h\r\n\r\n"); + for (i = 0; i < 20; i++) mg_mgr_poll(&mgr, 1); + ASSERT(ok == 2); + ASSERT(ok2 == 2); // MG_INFO(("-----> [%d] [%d]", ok, ok2)); mg_mgr_free(&mgr); ASSERT(mgr.conns == NULL);