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

Align code with RFC7230 section 3.3.3 which allows POST without a body.

Fixes:	#1783
parent 2367d528
......@@ -282,15 +282,19 @@ http1_body_status(struct http *hp, struct http_conn *htc)
htc->content_length = -1;
if (http_HdrIs(hp, H_Transfer_Encoding, "chunked")) {
http_Unset(hp, H_Content_Length);
cl = http_GetContentLength(hp);
if (http_GetHdr(hp, H_Transfer_Encoding, &b)) {
if (strcasecmp(b, "chunked"))
return (BS_ERROR);
if (cl != -1) {
/*
* RFC7230 3.3.3 allows more lenient handling
* but we're going to be strict.
*/
return (BS_ERROR);
}
return (BS_CHUNKED);
}
if (http_GetHdr(hp, H_Transfer_Encoding, &b))
return (BS_ERROR);
cl = http_GetContentLength(hp);
if (cl == -2)
return (BS_ERROR);
if (cl >= 0) {
......@@ -298,6 +302,9 @@ http1_body_status(struct http *hp, struct http_conn *htc)
return (cl == 0 ? BS_NONE : BS_LENGTH);
}
if (hp->protover == 11)
return (BS_NONE);
if (http_HdrIs(hp, H_Connection, "keep-alive")) {
/*
* Keep alive with neither TE=Chunked or C-Len is impossible.
......@@ -306,20 +313,6 @@ http1_body_status(struct http *hp, struct http_conn *htc)
return (BS_NONE);
}
if (http_HdrIs(hp, H_Connection, "close")) {
/*
* In this case, it is safe to just read what comes.
*/
return (BS_EOF);
}
if (hp->protover < 11) {
/*
* With no Connection header, assume EOF.
*/
return (BS_EOF);
}
/*
* Fall back to EOF transfer.
*/
......
......@@ -2,7 +2,7 @@ varnishtest "Check HTTP/1.0 EOF transmission"
server s1 {
rxreq
send "HTTP/1.1 200 OK\n"
send "HTTP/1.0 200 OK\n"
send "Connection: close\n"
send "\n"
send "Body line 1\n"
......
......@@ -4,7 +4,7 @@ feature SO_RCVTIMEO_WORKS
server s1 {
rxreq
send "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"
send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
delay 1.5
# send "Baba\n"
} -start
......
......@@ -4,7 +4,7 @@ feature SO_RCVTIMEO_WORKS
server s1 {
rxreq
send "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"
send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
delay 4.0
send "Baba\n"
} -start
......@@ -26,7 +26,7 @@ client c1 {
server s1 {
rxreq
send "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"
send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
delay 1.0
send "Baba\n"
delay 1.0
......
......@@ -4,7 +4,7 @@ feature SO_RCVTIMEO_WORKS
server s1 {
rxreq
send "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"
send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
delay 1.5
send "Baba\n"
} -start
......@@ -28,7 +28,7 @@ client c1 {
server s1 {
rxreq
send "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"
send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
delay 0.5
send "Baba\n"
delay 0.5
......
......@@ -3,7 +3,7 @@ varnishtest "Test parking second request on backend delay"
server s1 {
rxreq
expect req.url == "/foo"
send "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n"
send "HTTP/1.0 200 OK\r\nConnection: close\r\n\r\n"
delay .2
sema r1 sync 2
delay .2
......
......@@ -16,7 +16,7 @@ varnishtest "ESI spanning storage bits"
server s1 {
rxreq
expect req.url == "/foo/bar"
send "HTTP/1.1 200 OK\n"
send "HTTP/1.0 200 OK\n"
send "Connection: close\n"
send "\n"
send {
......
......@@ -3,7 +3,7 @@ varnishtest "Check <esi: detector"
server s1 {
rxreq
expect req.url == "/foo"
send "HTTP/1.1 200 OK\n"
send "HTTP/1.0 200 OK\n"
send "Connection: close\n"
send "\n"
send { <a> <esi/> }
......
......@@ -4,7 +4,7 @@ server s1 {
rxreq
expect req.http.accept-encoding == "gzip"
expect req.url == "/foo"
txresp -nolen -gziplen 4100
txresp -proto HTTP/1.0 -nolen -gziplen 4100
accept
rxreq
expect req.url == "/bar"
......
......@@ -2,7 +2,7 @@ varnishtest "HTTP/1.1 Backend sends no length hint"
server s1 {
rxreq
send "HTTP/1.1 200 OK\n"
send "HTTP/1.0 200 OK\n"
send "\n"
send "12345"
} -start
......
varnishtest "C-L/T-E:chunked conflict"
server s1 {
rxreqhdrs
expect req.http.content-length == <undef>
expect req.http.transfer-encoding == chunked
rxreqbody
expect req.url == /1
rxreq
expect req.bodylen == 20
send "HTTP/1.1 200 OK"
send "Content-Length: 31\r\n"
send "Transfer-Encoding: chunked\r\n"
send "\r\n"
send "14\r\n"
send "0123456789"
send "0123456789"
send "0\r\n"
send "\r\n"
rxreqhdrs
expect req.http.content-length == 20
expect req.http.transfer-encoding == <undef>
expect req.url == /2
expect req.bodylen == 20
send "HTTP/1.1 200 OK"
send "HTTP/1.1 200 OK\r\n"
send "Content-Length: 31\r\n"
send "Transfer-Encoding: chunked\r\n"
send "\r\n"
......@@ -36,14 +16,7 @@ server s1 {
} -start
varnish v1 -vcl+backend {
import ${vmod_std};
sub vcl_recv {
if (req.url == "/2") {
std.cache_req_body(1KB);
}
}
} -start
varnish v1 -vcl+backend { } -start
client c1 {
......@@ -56,12 +29,14 @@ client c1 {
send "0123456789"
send "0\r\n"
send "\r\n"
rxresp
expect resp.bodylen == 20
expect resp.status == 400
} -run
client c1 {
send "PUT /2 HTTP/1.1\r\n"
send "Content-Length: 31\r\n"
send "Transfer-Encoding: chunked\r\n"
send "\r\n"
send "14\r\n"
......@@ -69,7 +44,8 @@ client c1 {
send "0123456789"
send "0\r\n"
send "\r\n"
rxresp
expect resp.bodylen == 20
expect resp.status == 503
} -run
varnishtest "POST with no body"
server s1 {
rxreq
txresp -hdr "foo: 1"
rxreq
txresp -hdr "foo: 2"
} -start
varnish v1 -vcl+backend {} -start
client c1 {
txreq -req "POST" -nolen
rxresp
expect resp.http.foo == 1
txreq -req "POST" -nolen
rxresp
expect resp.http.foo == 2
} -run
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