]> err.no Git - varnish/commitdiff
For ESI responses we can only use Chunked encoding for HTTP/1.1 and
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 11 Oct 2008 11:28:52 +0000 (11:28 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 11 Oct 2008 11:28:52 +0000 (11:28 +0000)
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
varnish-cache/bin/varnishd/cache_vrt_esi.c
varnish-cache/bin/varnishtest/tests/e00012.vtc [new file with mode: 0644]

index ed3e4185c25d2a9a109736207306ae28cf890fd8..4cf2433d4c2c3e7ea51a7431c49203ad8447b069 100644 (file)
@@ -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))
index e3d80a0d706d262832016bf264cff55f8ed332d9..8eb52aa3a2379c64871327e09e9a563399bda3d2 100644 (file)
@@ -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 (file)
index 0000000..bea8462
--- /dev/null
@@ -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 {
+                <html>
+                Before include
+                <!--esi <esi:include src="body"/> -->
+                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