From 140ac74056e5c2b5ba1ab23e7da52de01c62babf Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 11 Oct 2008 11:28:52 +0000 Subject: [PATCH] For ESI responses we can only use Chunked encoding for HTTP/1.1 and later. Use EOF-encoding for sessions where the request is lower HTTP protocol versions. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3292 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_response.c | 8 +++- varnish-cache/bin/varnishd/cache_vrt_esi.c | 8 ++-- .../bin/varnishtest/tests/e00012.vtc | 46 +++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/tests/e00012.vtc diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index ed3e4185..4cf2433d 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -105,6 +105,10 @@ RES_BuildHttp(struct sess *sp) http_FilterFields(sp->wrk, sp->fd, sp->http, sp->obj->http, HTTPH_A_DELIVER); + /* Only HTTP 1.1 can do Chunked encoding */ + if (sp->http->protover < 1.1 && !VTAILQ_EMPTY(&sp->obj->esibits)) + http_Unset(sp->http, H_Transfer_Encoding); + TIM_format(TIM_real(), time_str); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", time_str); @@ -140,7 +144,7 @@ RES_WriteObj(struct sess *sp) if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) { ESI_Deliver(sp); } else if (sp->wantbody) { - if (sp->esis > 0) { + if (sp->esis > 0 && sp->http->protover >= 1.1) { sprintf(lenbuf, "%x\r\n", sp->obj->len); sp->wrk->acct.hdrbytes += WRK_Write(sp->wrk, lenbuf, -1); @@ -170,7 +174,7 @@ RES_WriteObj(struct sess *sp) WRK_Write(sp->wrk, st->ptr, st->len); } assert(u == sp->obj->len); - if (sp->esis > 0) + if (sp->esis > 0 && sp->http->protover >= 1.1) WRK_Write(sp->wrk, "\r\n", -1); } if (WRK_Flush(sp->wrk)) diff --git a/varnish-cache/bin/varnishd/cache_vrt_esi.c b/varnish-cache/bin/varnishd/cache_vrt_esi.c index e3d80a0d..8eb52aa3 100644 --- a/varnish-cache/bin/varnishd/cache_vrt_esi.c +++ b/varnish-cache/bin/varnishd/cache_vrt_esi.c @@ -802,9 +802,11 @@ ESI_Deliver(struct sess *sp) VTAILQ_FOREACH(eb, &sp->obj->esibits, list) { if (Tlen(eb->verbatim)) { - WRK_Write(sp->wrk, eb->chunk_length, -1); + if (sp->http->protover >= 1.1) + WRK_Write(sp->wrk, eb->chunk_length, -1); WRK_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim)); - WRK_Write(sp->wrk, "\r\n", -1); + if (sp->http->protover >= 1.1) + WRK_Write(sp->wrk, "\r\n", -1); } if (eb->include.b == NULL || sp->esis >= params->max_esi_includes) @@ -842,7 +844,7 @@ ESI_Deliver(struct sess *sp) sp->obj = obj; } - if (sp->esis == 0) + if (sp->esis == 0 && sp->http->protover >= 1.1) WRK_Write(sp->wrk, "0\r\n\r\n", -1); } diff --git a/varnish-cache/bin/varnishtest/tests/e00012.vtc b/varnish-cache/bin/varnishtest/tests/e00012.vtc new file mode 100644 index 00000000..bea84628 --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/e00012.vtc @@ -0,0 +1,46 @@ +# $Id$ + +test "ESI includes for pre HTTP/1.1 cannot used chunked encoding" + +server s1 { + rxreq + expect req.url == "/foo/bar" + txresp -body { + + Before include + + After include + } + rxreq + expect req.url == "/foo/body" + txresp -body { + Included file + } +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +client c1 { + txreq -url /foo/bar -proto HTTP/1.1 + rxresp + expect resp.status == 200 + expect resp.bodylen == 151 +} -run + +client c1 { + txreq -url /foo/bar -proto HTTP/1.0 + rxresp + expect resp.status == 200 + expect resp.bodylen == 151 +} -run + +client c1 { + txreq -url /foo/bar -proto "" + rxresp + expect resp.status == 200 + expect resp.bodylen == 151 +} -run -- 2.39.5