[master] a6a6e97 Align code with RFC7230 section 3.3.3 which allows POST without a body.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Sep 10 11:17:22 CEST 2015
commit a6a6e97a4db6e94b14f81af55fea4d07aa06d0af
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Sep 10 09:16:33 2015 +0000
Align code with RFC7230 section 3.3.3 which allows POST without a body.
Fixes: #1783
diff --git a/bin/varnishd/http1/cache_http1_proto.c b/bin/varnishd/http1/cache_http1_proto.c
index 77b8f5b..8fa7e9e 100644
--- a/bin/varnishd/http1/cache_http1_proto.c
+++ b/bin/varnishd/http1/cache_http1_proto.c
@@ -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.
*/
diff --git a/bin/varnishtest/tests/b00011.vtc b/bin/varnishtest/tests/b00011.vtc
index 82381a8..d6c9eab 100644
--- a/bin/varnishtest/tests/b00011.vtc
+++ b/bin/varnishtest/tests/b00011.vtc
@@ -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"
diff --git a/bin/varnishtest/tests/b00020.vtc b/bin/varnishtest/tests/b00020.vtc
index 1448ed5..d601501 100644
--- a/bin/varnishtest/tests/b00020.vtc
+++ b/bin/varnishtest/tests/b00020.vtc
@@ -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
diff --git a/bin/varnishtest/tests/b00021.vtc b/bin/varnishtest/tests/b00021.vtc
index 3d4e241..46be8cb 100644
--- a/bin/varnishtest/tests/b00021.vtc
+++ b/bin/varnishtest/tests/b00021.vtc
@@ -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
diff --git a/bin/varnishtest/tests/b00022.vtc b/bin/varnishtest/tests/b00022.vtc
index c232408..7bf6d95 100644
--- a/bin/varnishtest/tests/b00022.vtc
+++ b/bin/varnishtest/tests/b00022.vtc
@@ -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
diff --git a/bin/varnishtest/tests/c00013.vtc b/bin/varnishtest/tests/c00013.vtc
index 081ed1f..689e118 100644
--- a/bin/varnishtest/tests/c00013.vtc
+++ b/bin/varnishtest/tests/c00013.vtc
@@ -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
diff --git a/bin/varnishtest/tests/e00007.vtc b/bin/varnishtest/tests/e00007.vtc
index a03ef55..635f19e 100644
--- a/bin/varnishtest/tests/e00007.vtc
+++ b/bin/varnishtest/tests/e00007.vtc
@@ -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 {
diff --git a/bin/varnishtest/tests/e00014.vtc b/bin/varnishtest/tests/e00014.vtc
index 0097f13..0f90331 100644
--- a/bin/varnishtest/tests/e00014.vtc
+++ b/bin/varnishtest/tests/e00014.vtc
@@ -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/> }
diff --git a/bin/varnishtest/tests/g00002.vtc b/bin/varnishtest/tests/g00002.vtc
index 712d51b..1abdd8e 100644
--- a/bin/varnishtest/tests/g00002.vtc
+++ b/bin/varnishtest/tests/g00002.vtc
@@ -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"
diff --git a/bin/varnishtest/tests/r00733.vtc b/bin/varnishtest/tests/r00733.vtc
index 365f0ec..b6a1170 100644
--- a/bin/varnishtest/tests/r00733.vtc
+++ b/bin/varnishtest/tests/r00733.vtc
@@ -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
diff --git a/bin/varnishtest/tests/r01729.vtc b/bin/varnishtest/tests/r01729.vtc
index dd7e0da..a01bab2 100644
--- a/bin/varnishtest/tests/r01729.vtc
+++ b/bin/varnishtest/tests/r01729.vtc
@@ -1,30 +1,10 @@
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
diff --git a/bin/varnishtest/tests/r01783.vtc b/bin/varnishtest/tests/r01783.vtc
new file mode 100644
index 0000000..c44b77f
--- /dev/null
+++ b/bin/varnishtest/tests/r01783.vtc
@@ -0,0 +1,19 @@
+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
More information about the varnish-commit
mailing list