r5478 - in trunk/varnish-cache: bin/varnishd include

phk at varnish-cache.org phk at varnish-cache.org
Wed Oct 27 20:48:40 CEST 2010


Author: phk
Date: 2010-10-27 20:48:40 +0200 (Wed, 27 Oct 2010)
New Revision: 5478

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/rfc2616.c
   trunk/varnish-cache/include/vsc_fields.h
   trunk/varnish-cache/include/vsl_tags.h
Log:
Special case beresp status 1xx, 204 and 304, they have no body.

(r5477 is a requirement for this fix)

Fixes: #803



Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2010-10-27 18:07:51 UTC (rev 5477)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2010-10-27 18:48:40 UTC (rev 5478)
@@ -476,13 +476,14 @@
 	 * Determine if we have a body or not
 	 * XXX: Missing:  RFC2616 sec. 4.4 in re 1xx, 204 & 304 responses
 	 */
-	cls = 0;
-	mklen = 0;
 
 	switch (sp->wrk->body_status) {
 	case BS_NONE:
+		cls = 0;
+		mklen = 0;
 		break;
 	case BS_ZERO:
+		cls = 0;
 		mklen = 1;
 		break;
 	case BS_LENGTH:
@@ -499,12 +500,23 @@
 		mklen = 1;
 		break;
 	case BS_ERROR:
-		VDI_CloseFd(sp);
-		return (__LINE__);
+		cls = 1;
+		mklen = 0;
+		break;
 	default:
+		cls = 0;
+		mklen = 0;
 		INCOMPL();
 	}
 
+	WSL(sp->wrk, SLT_Fetch_Body, sp->vbc->fd, "%u %u %u",
+	    sp->wrk->body_status, cls, mklen);
+
+	if (sp->wrk->body_status == BS_ERROR) {
+		VDI_CloseFd(sp);
+		return (__LINE__);
+	}
+
 	if (cls == 0 && http_HdrIs(hp, H_Connection, "close"))
 		cls = 1;
 

Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c	2010-10-27 18:07:51 UTC (rev 5477)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c	2010-10-27 18:48:40 UTC (rev 5478)
@@ -166,7 +166,6 @@
 
 /*--------------------------------------------------------------------
  * Body existence and fetch method
- * XXX: Missing:  RFC2616 sec. 4.4 in re 1xx, 204 & 304 responses
  */
 
 enum body_status
@@ -181,6 +180,7 @@
 		/*
 		 * A HEAD request can never have a body in the reply,
 		 * no matter what the headers might say.
+		 * [RFC2516 4.3 p33]
 		 */
 		sp->wrk->stats.fetch_head++;
 		return (BS_NONE);
@@ -203,6 +203,33 @@
 		return (BS_ERROR);
 	}
 
+	if (hp->status <= 199) {
+		/*
+		 * 1xx responses never have a body.
+		 * [RFC2616 4.3 p33]
+		 */
+		sp->wrk->stats.fetch_1xx++;
+		return (BS_NONE);
+	}
+
+	if (hp->status == 204) {
+		/*
+		 * 204 is "No Content", obviously don't expect a body.
+		 * [RFC2616 10.2.5 p60]
+		 */
+		sp->wrk->stats.fetch_204++;
+		return (BS_NONE);
+	}
+
+	if (hp->status == 304) {
+		/*
+		 * 304 is "Not Modified" it has no body.
+		 * [RFC2616 10.3.5 p63]
+		 */
+		sp->wrk->stats.fetch_304++;
+		return (BS_NONE);
+	}
+
 	if (http_HdrIs(hp, H_Connection, "keep-alive")) {
 		/*
 		 * Keep alive with neither TE=Chunked or C-Len is impossible.
@@ -229,7 +256,7 @@
 	}
 
 	/*
-	 * XXX: Here it should depends on the status code
+	 * Fall back to EOF transfer.
 	 */
 	sp->wrk->stats.fetch_eof++;
 	return (BS_EOF);

Modified: trunk/varnish-cache/include/vsc_fields.h
===================================================================
--- trunk/varnish-cache/include/vsc_fields.h	2010-10-27 18:07:51 UTC (rev 5477)
+++ trunk/varnish-cache/include/vsc_fields.h	2010-10-27 18:48:40 UTC (rev 5478)
@@ -56,14 +56,17 @@
 VSC_F(backend_retry,	uint64_t, 0, 'a', "Backend conn. retry")
 
 VSC_F(fetch_head,		uint64_t, 1, 'a', "Fetch head")
-VSC_F(fetch_length,	uint64_t, 1, 'a', "Fetch with Length")
-VSC_F(fetch_chunked,	uint64_t, 1, 'a', "Fetch chunked")
+VSC_F(fetch_length,		uint64_t, 1, 'a', "Fetch with Length")
+VSC_F(fetch_chunked,		uint64_t, 1, 'a', "Fetch chunked")
 VSC_F(fetch_eof,		uint64_t, 1, 'a', "Fetch EOF")
 VSC_F(fetch_bad,		uint64_t, 1, 'a', "Fetch had bad headers")
 VSC_F(fetch_close,		uint64_t, 1, 'a', "Fetch wanted close")
-VSC_F(fetch_oldhttp,	uint64_t, 1, 'a', "Fetch pre HTTP/1.1 closed")
+VSC_F(fetch_oldhttp,		uint64_t, 1, 'a', "Fetch pre HTTP/1.1 closed")
 VSC_F(fetch_zero,		uint64_t, 1, 'a', "Fetch zero len")
-VSC_F(fetch_failed,	uint64_t, 1, 'a', "Fetch failed")
+VSC_F(fetch_failed,		uint64_t, 1, 'a', "Fetch failed")
+VSC_F(fetch_1xx,		uint64_t, 1, 'a', "Fetch no body (1xx)")
+VSC_F(fetch_204,		uint64_t, 1, 'a', "Fetch no body (204)")
+VSC_F(fetch_304,		uint64_t, 1, 'a', "Fetch no body (304)")
 
 
 VSC_F(n_sess_mem,		uint64_t, 0, 'i', "N struct sess_mem")

Modified: trunk/varnish-cache/include/vsl_tags.h
===================================================================
--- trunk/varnish-cache/include/vsl_tags.h	2010-10-27 18:07:51 UTC (rev 5477)
+++ trunk/varnish-cache/include/vsl_tags.h	2010-10-27 18:48:40 UTC (rev 5478)
@@ -79,6 +79,7 @@
 SLTM(LostHeader)
 
 SLTM(TTL)
+SLTM(Fetch_Body)
 SLTM(VCL_acl)
 SLTM(VCL_call)
 SLTM(VCL_trace)




More information about the varnish-commit mailing list