Commit e7414b58 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use the protocol specific info to determine precense of request body.

parent 972273fb
...@@ -77,7 +77,6 @@ ...@@ -77,7 +77,6 @@
#include "hash/hash_slinger.h" #include "hash/hash_slinger.h"
#include "vcl.h" #include "vcl.h"
#include "vct.h"
#include "vtcp.h" #include "vtcp.h"
#include "vtim.h" #include "vtim.h"
...@@ -256,37 +255,6 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -256,37 +255,6 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
} }
} }
/*----------------------------------------------------------------------
*/
static enum req_body_state_e
http1_req_body_status(struct req *req)
{
char *ptr, *endp;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
if (http_GetHdr(req->http, H_Content_Length, &ptr)) {
AN(ptr);
if (*ptr == '\0')
return (REQ_BODY_FAIL);
req->req_bodybytes = strtoul(ptr, &endp, 10);
if (*endp != '\0' && !vct_islws(*endp))
return (REQ_BODY_FAIL);
if (req->req_bodybytes == 0)
return (REQ_BODY_NONE);
req->h1.bytes_yet = req->req_bodybytes - req->h1.bytes_done;
return (REQ_BODY_PRESENT);
}
if (http_HdrIs(req->http, H_Transfer_Encoding, "chunked")) {
req->h1.chunk_ctr = -1;
return (REQ_BODY_CHUNKED);
}
if (http_GetHdr(req->http, H_Transfer_Encoding, NULL))
return (REQ_BODY_FAIL);
return (REQ_BODY_NONE);
}
/*---------------------------------------------------------------------- /*----------------------------------------------------------------------
*/ */
...@@ -295,7 +263,6 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -295,7 +263,6 @@ http1_dissect(struct worker *wrk, struct req *req)
{ {
const char *r_100 = "HTTP/1.1 100 Continue\r\n\r\n"; const char *r_100 = "HTTP/1.1 100 Continue\r\n\r\n";
const char *r_400 = "HTTP/1.1 400 Bad Request\r\n\r\n"; const char *r_400 = "HTTP/1.1 400 Bad Request\r\n\r\n";
const char *r_411 = "HTTP/1.1 411 Length Required\r\n\r\n";
const char *r_417 = "HTTP/1.1 417 Expectation Failed\r\n\r\n"; const char *r_417 = "HTTP/1.1 417 Expectation Failed\r\n\r\n";
char *p; char *p;
ssize_t r; ssize_t r;
...@@ -335,18 +302,22 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -335,18 +302,22 @@ http1_dissect(struct worker *wrk, struct req *req)
return (REQ_FSM_DONE); return (REQ_FSM_DONE);
} }
if (req->req_body_status == REQ_BODY_INIT) if (req->req_body_status != REQ_BODY_INIT) {
req->req_body_status = http1_req_body_status(req);
else
assert(req->req_body_status == REQ_BODY_NONE); // ESI assert(req->req_body_status == REQ_BODY_NONE); // ESI
} else if (req->htc->body_status == BS_CHUNKED) {
if (req->req_body_status == REQ_BODY_FAIL) { req->h1.chunk_ctr = -1;
wrk->stats.client_req_411++; req->req_body_status = REQ_BODY_CHUNKED;
r = write(req->sp->fd, r_411, strlen(r_411)); } else if (req->htc->body_status == BS_LENGTH) {
if (r > 0) req->req_bodybytes = req->htc->content_length;
req->acct.resp_hdrbytes += r; req->h1.bytes_yet = req->req_bodybytes - req->h1.bytes_done;
SES_Close(req->sp, SC_RX_JUNK); req->req_body_status = REQ_BODY_PRESENT;
return (REQ_FSM_DONE); } else if (req->htc->body_status == BS_NONE) {
req->req_body_status = REQ_BODY_NONE;
} else if (req->htc->body_status == BS_EOF) {
/* XXX: We don't support EOF bodies in requests */
req->req_body_status = REQ_BODY_NONE;
} else {
WRONG("Unknown req.body_length situation");
} }
if (http_GetHdr(req->http, H_Expect, &p)) { if (http_GetHdr(req->http, H_Expect, &p)) {
...@@ -366,6 +337,7 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -366,6 +337,7 @@ http1_dissect(struct worker *wrk, struct req *req)
SES_Close(req->sp, SC_REM_CLOSE); SES_Close(req->sp, SC_REM_CLOSE);
return (REQ_FSM_DONE); return (REQ_FSM_DONE);
} }
http_Unset(req->http, H_Expect);
} }
wrk->stats.client_req++; wrk->stats.client_req++;
...@@ -375,8 +347,6 @@ http1_dissect(struct worker *wrk, struct req *req) ...@@ -375,8 +347,6 @@ http1_dissect(struct worker *wrk, struct req *req)
req->ws_req = WS_Snapshot(req->ws); req->ws_req = WS_Snapshot(req->ws);
req->doclose = req->http->doclose; req->doclose = req->http->doclose;
http_Unset(req->http, H_Expect);
assert(req->req_body_status != REQ_BODY_INIT); assert(req->req_body_status != REQ_BODY_INIT);
HTTP_Copy(req->http0, req->http); // For ESI & restart HTTP_Copy(req->http0, req->http); // For ESI & restart
......
...@@ -522,9 +522,8 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp) ...@@ -522,9 +522,8 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp)
http1_proto_ver(hp); http1_proto_ver(hp);
retval = http1_request_check_host_hdr(hp); retval = http1_request_check_host_hdr(hp);
if (retval != 0) { if (retval != 0)
return (retval); return (retval);
}
/* RFC2616, section 5.2, point 1 */ /* RFC2616, section 5.2, point 1 */
if (!strncasecmp(hp->hd[HTTP_HDR_URL].b, "http://", 7)) { if (!strncasecmp(hp->hd[HTTP_HDR_URL].b, "http://", 7)) {
...@@ -540,6 +539,9 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp) ...@@ -540,6 +539,9 @@ HTTP1_DissectRequest(struct http_conn *htc, struct http *hp)
htc->body_status = http1_body_status(hp, htc); htc->body_status = http1_body_status(hp, htc);
if (htc->body_status == BS_ERROR)
return (400);
hp->doclose = http1_DoConnection(hp); hp->doclose = http1_DoConnection(hp);
return (retval); return (retval);
......
...@@ -10,13 +10,13 @@ varnish v1 -vcl+backend { } -start ...@@ -10,13 +10,13 @@ varnish v1 -vcl+backend { } -start
client c1 { client c1 {
txreq -req POST -nolen -hdr "Transfer-Encoding: carrier-pigeon" txreq -req POST -nolen -hdr "Transfer-Encoding: carrier-pigeon"
rxresp rxresp
expect resp.status == 411 expect resp.status == 400
} -run } -run
client c1 { client c1 {
txreq -req POST -nolen -hdr "Content-Length: carrier-pigeon" txreq -req POST -nolen -hdr "Content-Length: carrier-pigeon"
rxresp rxresp
expect resp.status == 411 expect resp.status == 400
} -run } -run
client c1 { client c1 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment