[master] 2eae667 Make range-stuff 4GB+ compliant Start streaming response code
Poul-Henning Kamp
phk at varnish-cache.org
Mon Apr 11 11:18:38 CEST 2011
commit 2eae66796c08050cfd0b340cdfb24d8f6c774b7c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Apr 11 09:18:08 2011 +0000
Make range-stuff 4GB+ compliant
Start streaming response code
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 95a8dbf..d280bb1 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -856,6 +856,8 @@ void WSL_Flush(struct worker *w, int overflow);
/* cache_response.c */
void RES_BuildHttp(struct sess *sp);
void RES_WriteObj(struct sess *sp);
+void RES_StreamStart(struct sess *sp);
+void RES_StreamEnd(struct sess *sp);
/* cache_vary.c */
struct vsb *VRY_Create(const struct sess *sp, const struct http *hp);
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 5045c2c..1c1118c 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -709,6 +709,8 @@ cnt_fetchbody(struct sess *sp)
if (sp->wrk->do_esi)
sp->wrk->do_stream = 0;
+ if (!sp->wantbody)
+ sp->wrk->do_stream = 0;
l = http_EstimateWS(sp->wrk->beresp,
pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
@@ -841,6 +843,8 @@ cnt_streambody(struct sess *sp)
{
int i;
+ RES_StreamStart(sp);
+
/* Use unmodified headers*/
i = FetchBody(sp);
@@ -867,7 +871,16 @@ cnt_streambody(struct sess *sp)
HSH_Unbusy(sp);
}
sp->acct_tmp.fetch++;
- sp->step = STP_DELIVER;
+ sp->director = NULL;
+ sp->restarts = 0;
+
+ RES_StreamEnd(sp);
+
+ assert(WRW_IsReleased(sp->wrk));
+ assert(sp->wrk->wrw.ciov == sp->wrk->wrw.siov);
+ (void)HSH_Deref(sp->wrk, NULL, &sp->obj);
+ http_Setup(sp->wrk->resp, NULL);
+ sp->step = STP_DONE;
return (0);
}
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 87f6f6f..4771c54 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -125,9 +125,9 @@ res_do_conds(struct sess *sp)
/*--------------------------------------------------------------------*/
static void
-res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh)
+res_dorange(struct sess *sp, const char *r, ssize_t *plow, ssize_t *phigh)
{
- unsigned low, high, has_low;
+ ssize_t low, high, has_low;
(void)sp;
if (strncmp(r, "bytes=", 6))
@@ -176,11 +176,12 @@ res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh)
return;
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
- "Content-Range: bytes %u-%u/%u", low, high, sp->obj->len);
+ "Content-Range: bytes %jd-%jd/%jd",
+ (intmax_t)low, (intmax_t)high, (intmax_t)sp->obj->len);
http_Unset(sp->wrk->resp, H_Content_Length);
assert(sp->wrk->res_mode & RES_LEN);
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
- "Content-Length: %u", 1 + high - low);
+ "Content-Length: %jd", (intmax_t)(1 + high - low));
http_SetResp(sp->wrk->resp, "HTTP/1.1", 206, "Partial Content");
*plow = low;
@@ -337,7 +338,7 @@ void
RES_WriteObj(struct sess *sp)
{
char *r;
- unsigned low, high;
+ ssize_t low, high;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -390,3 +391,45 @@ RES_WriteObj(struct sess *sp)
if (WRW_FlushRelease(sp->wrk))
vca_close_session(sp, "remote closed");
}
+
+/*--------------------------------------------------------------------*/
+
+void
+RES_StreamStart(struct sess *sp)
+{
+
+ AZ(sp->wrk->res_mode & RES_ESI_CHILD);
+ AN(sp->wantbody);
+
+ WRW_Reserve(sp->wrk, &sp->fd);
+ /*
+ * Always remove C-E if client don't grok it
+ */
+ if (sp->wrk->res_mode & RES_GUNZIP)
+ http_Unset(sp->wrk->resp, H_Content_Encoding);
+
+ sp->acct_tmp.hdrbytes +=
+ http_Write(sp->wrk, sp->wrk->resp, 1);
+
+ if (sp->wrk->res_mode & RES_CHUNKED)
+ WRW_Chunked(sp->wrk);
+}
+
+void
+RES_StreamEnd(struct sess *sp)
+{
+ ssize_t low, high;
+
+ if (sp->wrk->res_mode & RES_GUNZIP) {
+ res_WriteGunzipObj(sp);
+ } else {
+ low = 0;
+ high = sp->obj->len - 1;
+ res_WriteDirObj(sp, low, high);
+ }
+ if (sp->wrk->res_mode & RES_CHUNKED &&
+ !(sp->wrk->res_mode & RES_ESI_CHILD))
+ WRW_EndChunk(sp->wrk);
+ if (WRW_FlushRelease(sp->wrk))
+ vca_close_session(sp, "remote closed");
+}
More information about the varnish-commit
mailing list