r3292 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at projects.linpro.no phk at projects.linpro.no
Sat Oct 11 13:28:53 CEST 2008


Author: phk
Date: 2008-10-11 13:28:52 +0200 (Sat, 11 Oct 2008)
New Revision: 3292

Added:
   trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c
Log:
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.



Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2008-10-11 11:27:56 UTC (rev 3291)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2008-10-11 11:28:52 UTC (rev 3292)
@@ -105,6 +105,10 @@
 	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 @@
 	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 @@
 			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))

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c	2008-10-11 11:27:56 UTC (rev 3291)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c	2008-10-11 11:28:52 UTC (rev 3292)
@@ -802,9 +802,11 @@
 
 	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 @@
 		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);
 }
 

Added: trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc	2008-10-11 11:28:52 UTC (rev 3292)
@@ -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




More information about the varnish-commit mailing list