From 24e2d25340531720f8912d14715fe3d8ac6badc4 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 19 Sep 2008 20:49:30 +0000 Subject: [PATCH] Implement correct handling of the Expect: header. Fixes #309 git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3206 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_center.c | 17 +++++++++++++++ varnish-cache/bin/varnishd/default.vcl | 4 ---- .../bin/varnishtest/tests/c00018.vtc | 21 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/tests/c00018.vtc diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 097a739d..63355b01 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -889,6 +889,8 @@ static int cnt_start(struct sess *sp) { int done; + char *p; + const char *r = "HTTP/1.1 100 Continue\r\n\r\n"; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); AZ(sp->restarts); @@ -929,6 +931,21 @@ cnt_start(struct sess *sp) /* XXX: Handle TRACE & OPTIONS of Max-Forwards = 0 */ + /* + * Handle Expect headers + */ + if (http_GetHdr(sp->http, H_Expect, &p)) { + if (strcmp(p, "100-continue")) { + sp->err_code = 417; + sp->step = STP_ERROR; + return (0); + } + + /* XXX: Don't bother with write failures for now */ + (void)write(sp->fd, r, strlen(r)); + http_Unset(sp->http, H_Expect); + } + sp->step = STP_RECV; return (0); } diff --git a/varnish-cache/bin/varnishd/default.vcl b/varnish-cache/bin/varnishd/default.vcl index d55d9488..febfa8b0 100644 --- a/varnish-cache/bin/varnishd/default.vcl +++ b/varnish-cache/bin/varnishd/default.vcl @@ -49,10 +49,6 @@ sub vcl_recv { /* Non-RFC2616 or CONNECT which is weird. */ pipe; } - if (req.http.Expect) { - /* Expect is just too hard at present. */ - pipe; - } if (req.request != "GET" && req.request != "HEAD") { /* We only deal with GET and HEAD by default */ pass; diff --git a/varnish-cache/bin/varnishtest/tests/c00018.vtc b/varnish-cache/bin/varnishtest/tests/c00018.vtc new file mode 100644 index 00000000..558f5505 --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/c00018.vtc @@ -0,0 +1,21 @@ +# $Id$ + +test "Check Expect headers" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq -url "/" -req POST -hdr "Expect: 100-continue " -body "foo" + rxresp + expect resp.status == 100 + rxresp + expect resp.status == 200 + txreq -url "/" -req POST -hdr "Expect: 101-continue" -body "foo" + rxresp + expect resp.status == 417 +} -run -- 2.39.5