r5685 - trunk/varnish-cache/bin/varnishd
phk at varnish-cache.org
phk at varnish-cache.org
Wed Jan 5 12:13:30 CET 2011
Author: phk
Date: 2011-01-05 12:13:30 +0100 (Wed, 05 Jan 2011)
New Revision: 5685
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Centralize the "how do we deliver this ?" magic into a
sp->wrk variable where everybody can find it.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2011-01-05 10:26:24 UTC (rev 5684)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2011-01-05 11:13:30 UTC (rev 5685)
@@ -265,6 +265,15 @@
double first_byte_timeout;
double between_bytes_timeout;
+ /* Delivery mode */
+ unsigned res_mode;
+#define RES_LEN (1<<1)
+#define RES_EOF (1<<2)
+#define RES_CHUNKED (1<<3)
+#define RES_ESI (1<<4)
+#define RES_ESI_CHILD (1<<5)
+#define RES_GUNZIP (1<<6)
+
};
/* Work Request for worker thread ------------------------------------*/
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2011-01-05 10:26:24 UTC (rev 5684)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2011-01-05 11:13:30 UTC (rev 5685)
@@ -166,6 +166,35 @@
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
+ sp->wrk->res_mode = RES_LEN;
+
+ if (!sp->disable_esi && sp->obj->esidata != NULL) {
+ /* In ESI mode, we don't know the aggregate length */
+ sp->wrk->res_mode &= ~RES_LEN;
+ }
+
+ if (params->http_gzip_support &&
+ http_HdrIs(sp->obj->http, H_Content_Encoding, "gzip") &&
+ !RFC2616_Req_Gzip(sp) &&
+ sp->wantbody) {
+ /*
+ * We don't know what it uncompresses to
+ * XXX: we could cache that
+ */
+ sp->wrk->res_mode &= ~RES_LEN;
+ sp->wrk->res_mode |= RES_EOF; /* XXX */
+ sp->wrk->res_mode |= RES_GUNZIP;
+ }
+
+ if (!(sp->wrk->res_mode & (RES_LEN|RES_CHUNKED|RES_EOF))) {
+ if(sp->http->protover >= 1.1) {
+ sp->wrk->res_mode |= RES_CHUNKED;
+ } else {
+ sp->wrk->res_mode |= RES_EOF;
+ sp->doclose = "EOF mode";
+ }
+ }
+
sp->t_resp = TIM_real();
if (sp->obj->objcore != NULL) {
if ((sp->t_resp - sp->obj->last_lru) > params->lru_timeout)
@@ -199,13 +228,7 @@
sp->director = NULL;
sp->restarts = 0;
- if (params->http_gzip_support &&
- http_HdrIs(sp->wrk->resp, H_Content_Encoding, "gzip") &&
- !RFC2616_Req_Gzip(sp) &&
- sp->wantbody)
- RES_WriteGunzipObj(sp);
- else
- RES_WriteObj(sp);
+ RES_WriteObj(sp);
AZ(sp->wrk->wfd);
(void)HSH_Deref(sp->wrk, NULL, &sp->obj);
Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c 2011-01-05 10:26:24 UTC (rev 5684)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c 2011-01-05 11:13:30 UTC (rev 5685)
@@ -205,18 +205,17 @@
http_FilterFields(sp->wrk, sp->fd, sp->wrk->resp, sp->obj->http,
HTTPH_A_DELIVER);
- /* Only HTTP 1.1 can do Chunked encoding */
- if (!sp->disable_esi && sp->obj->esidata != NULL) {
+ if (!(sp->wrk->res_mode & RES_LEN)) {
http_Unset(sp->wrk->resp, H_Content_Length);
- if(sp->http->protover >= 1.1)
- http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
- "Transfer-Encoding: chunked");
- else
- sp->doclose = "ESI EOF";
- } else if (params->http_range_support)
+ } else if (params->http_range_support) {
+ /* We only accept ranges if we know the length */
http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Accept-Ranges: bytes");
+ }
+ if (sp->wrk->res_mode & RES_CHUNKED)
+ http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
+ "Transfer-Encoding: chunked");
TIM_format(TIM_real(), time_str);
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", time_str);
@@ -247,6 +246,11 @@
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ if (sp->wrk->res_mode & RES_GUNZIP) {
+ RES_WriteGunzipObj(sp);
+ return;
+ }
+
WRW_Reserve(sp->wrk, &sp->fd);
/*
More information about the varnish-commit
mailing list