Commit 2eae6679 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make range-stuff 4GB+ compliant

Start streaming response code
parent e6b43a53
......@@ -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);
......
......@@ -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);
}
......
......@@ -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");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment