Commit 7ec9794e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move res_mode from worker to req

parent d3f869a0
...@@ -343,15 +343,6 @@ struct worker { ...@@ -343,15 +343,6 @@ struct worker {
double first_byte_timeout; double first_byte_timeout;
double between_bytes_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)
/* Temporary accounting */ /* Temporary accounting */
struct acct acct_tmp; struct acct acct_tmp;
}; };
...@@ -626,6 +617,14 @@ struct req { ...@@ -626,6 +617,14 @@ struct req {
ssize_t l_crc; ssize_t l_crc;
uint32_t crc; uint32_t crc;
/* 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)
}; };
......
...@@ -216,26 +216,26 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -216,26 +216,26 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req)
AssertObjCorePassOrBusy(req->obj->objcore); AssertObjCorePassOrBusy(req->obj->objcore);
} }
wrk->res_mode = 0; req->res_mode = 0;
if (wrk->busyobj == NULL) if (wrk->busyobj == NULL)
wrk->res_mode |= RES_LEN; req->res_mode |= RES_LEN;
if (wrk->busyobj != NULL && if (wrk->busyobj != NULL &&
(wrk->busyobj->h_content_length != NULL || (wrk->busyobj->h_content_length != NULL ||
!wrk->busyobj->do_stream) && !wrk->busyobj->do_stream) &&
!wrk->busyobj->do_gzip && !wrk->busyobj->do_gunzip) !wrk->busyobj->do_gzip && !wrk->busyobj->do_gunzip)
wrk->res_mode |= RES_LEN; req->res_mode |= RES_LEN;
if (!req->disable_esi && req->obj->esidata != NULL) { if (!req->disable_esi && req->obj->esidata != NULL) {
/* In ESI mode, we don't know the aggregate length */ /* In ESI mode, we don't know the aggregate length */
wrk->res_mode &= ~RES_LEN; req->res_mode &= ~RES_LEN;
wrk->res_mode |= RES_ESI; req->res_mode |= RES_ESI;
} }
if (req->esi_level > 0) { if (req->esi_level > 0) {
wrk->res_mode &= ~RES_LEN; req->res_mode &= ~RES_LEN;
wrk->res_mode |= RES_ESI_CHILD; req->res_mode |= RES_ESI_CHILD;
} }
if (cache_param->http_gzip_support && req->obj->gziped && if (cache_param->http_gzip_support && req->obj->gziped &&
...@@ -244,24 +244,24 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -244,24 +244,24 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req)
* We don't know what it uncompresses to * We don't know what it uncompresses to
* XXX: we could cache that * XXX: we could cache that
*/ */
wrk->res_mode &= ~RES_LEN; req->res_mode &= ~RES_LEN;
wrk->res_mode |= RES_GUNZIP; req->res_mode |= RES_GUNZIP;
} }
if (!(wrk->res_mode & (RES_LEN|RES_CHUNKED|RES_EOF))) { if (!(req->res_mode & (RES_LEN|RES_CHUNKED|RES_EOF))) {
if (req->obj->len == 0 && if (req->obj->len == 0 &&
(wrk->busyobj == NULL || !wrk->busyobj->do_stream)) (wrk->busyobj == NULL || !wrk->busyobj->do_stream))
/* /*
* If the object is empty, neither ESI nor GUNZIP * If the object is empty, neither ESI nor GUNZIP
* can make it any different size * can make it any different size
*/ */
wrk->res_mode |= RES_LEN; req->res_mode |= RES_LEN;
else if (!req->wantbody) { else if (!req->wantbody) {
/* Nothing */ /* Nothing */
} else if (req->http->protover >= 11) { } else if (req->http->protover >= 11) {
wrk->res_mode |= RES_CHUNKED; req->res_mode |= RES_CHUNKED;
} else { } else {
wrk->res_mode |= RES_EOF; req->res_mode |= RES_EOF;
req->doclose = "EOF mode"; req->doclose = "EOF mode";
} }
} }
......
...@@ -60,7 +60,7 @@ ved_include(struct sess *sp, const char *src, const char *host) ...@@ -60,7 +60,7 @@ ved_include(struct sess *sp, const char *src, const char *host)
obj = sp->req->obj; obj = sp->req->obj;
sp->req->obj = NULL; sp->req->obj = NULL;
res_mode = sp->wrk->res_mode; res_mode = sp->req->res_mode;
/* Reset request to status before we started messing with it */ /* Reset request to status before we started messing with it */
HTTP_Copy(sp->req->http, sp->req->http0); HTTP_Copy(sp->req->http, sp->req->http0);
...@@ -107,14 +107,14 @@ ved_include(struct sess *sp, const char *src, const char *host) ...@@ -107,14 +107,14 @@ ved_include(struct sess *sp, const char *src, const char *host)
assert(sp->step == STP_DONE); assert(sp->step == STP_DONE);
sp->req->esi_level--; sp->req->esi_level--;
sp->req->obj = obj; sp->req->obj = obj;
sp->wrk->res_mode = res_mode; sp->req->res_mode = res_mode;
/* Reset the workspace */ /* Reset the workspace */
WS_Reset(sp->req->ws, sp_ws_wm); WS_Reset(sp->req->ws, sp_ws_wm);
WS_Reset(w->aws, wrk_ws_wm); /* XXX ? */ WS_Reset(w->aws, wrk_ws_wm); /* XXX ? */
WRW_Reserve(sp->wrk, &sp->fd); WRW_Reserve(sp->wrk, &sp->fd);
if (sp->wrk->res_mode & RES_CHUNKED) if (sp->req->res_mode & RES_CHUNKED)
WRW_Chunked(sp->wrk); WRW_Chunked(sp->wrk);
} }
...@@ -247,7 +247,7 @@ ESI_Deliver(struct sess *sp) ...@@ -247,7 +247,7 @@ ESI_Deliver(struct sess *sp)
* Only the top level document gets to decide this. * Only the top level document gets to decide this.
*/ */
sp->req->gzip_resp = 0; sp->req->gzip_resp = 0;
if (isgzip && !(sp->wrk->res_mode & RES_GUNZIP)) { if (isgzip && !(sp->req->res_mode & RES_GUNZIP)) {
assert(sizeof gzip_hdr == 10); assert(sizeof gzip_hdr == 10);
/* Send out the gzip header */ /* Send out the gzip header */
(void)WRW_Write(sp->wrk, gzip_hdr, 10); (void)WRW_Write(sp->wrk, gzip_hdr, 10);
......
...@@ -94,7 +94,7 @@ res_dorange(const struct sess *sp, const char *r, ssize_t *plow, ssize_t *phigh) ...@@ -94,7 +94,7 @@ res_dorange(const struct sess *sp, const char *r, ssize_t *plow, ssize_t *phigh)
"Content-Range: bytes %jd-%jd/%jd", "Content-Range: bytes %jd-%jd/%jd",
(intmax_t)low, (intmax_t)high, (intmax_t)req->obj->len); (intmax_t)low, (intmax_t)high, (intmax_t)req->obj->len);
http_Unset(req->resp, H_Content_Length); http_Unset(req->resp, H_Content_Length);
assert(sp->wrk->res_mode & RES_LEN); assert(req->res_mode & RES_LEN);
http_PrintfHeader(sp->wrk, sp->vsl_id, req->resp, http_PrintfHeader(sp->wrk, sp->vsl_id, req->resp,
"Content-Length: %jd", (intmax_t)(1 + high - low)); "Content-Length: %jd", (intmax_t)(1 + high - low));
http_SetResp(req->resp, "HTTP/1.1", 206, "Partial Content"); http_SetResp(req->resp, "HTTP/1.1", 206, "Partial Content");
...@@ -119,7 +119,7 @@ RES_BuildHttp(const struct sess *sp) ...@@ -119,7 +119,7 @@ RES_BuildHttp(const struct sess *sp)
req->resp->logtag = HTTP_Tx; req->resp->logtag = HTTP_Tx;
http_FilterResp(sp, req->obj->http, req->resp, 0); http_FilterResp(sp, req->obj->http, req->resp, 0);
if (!(sp->wrk->res_mode & RES_LEN)) { if (!(req->res_mode & RES_LEN)) {
http_Unset(req->resp, H_Content_Length); http_Unset(req->resp, H_Content_Length);
} else if (cache_param->http_range_support) { } else if (cache_param->http_range_support) {
/* We only accept ranges if we know the length */ /* We only accept ranges if we know the length */
...@@ -127,7 +127,7 @@ RES_BuildHttp(const struct sess *sp) ...@@ -127,7 +127,7 @@ RES_BuildHttp(const struct sess *sp)
"Accept-Ranges: bytes"); "Accept-Ranges: bytes");
} }
if (sp->wrk->res_mode & RES_CHUNKED) if (req->res_mode & RES_CHUNKED)
http_SetHeader(sp->wrk, sp->vsl_id, req->resp, http_SetHeader(sp->wrk, sp->vsl_id, req->resp,
"Transfer-Encoding: chunked"); "Transfer-Encoding: chunked");
...@@ -260,8 +260,8 @@ RES_WriteObj(struct sess *sp) ...@@ -260,8 +260,8 @@ RES_WriteObj(struct sess *sp)
high = req->obj->len - 1; high = req->obj->len - 1;
if ( if (
req->wantbody && req->wantbody &&
(sp->wrk->res_mode & RES_LEN) && (req->res_mode & RES_LEN) &&
!(sp->wrk->res_mode & (RES_ESI|RES_ESI_CHILD|RES_GUNZIP)) && !(req->res_mode & (RES_ESI|RES_ESI_CHILD|RES_GUNZIP)) &&
cache_param->http_range_support && cache_param->http_range_support &&
req->obj->response == 200 && req->obj->response == 200 &&
http_GetHdr(req->http, H_Range, &r)) http_GetHdr(req->http, H_Range, &r))
...@@ -270,41 +270,41 @@ RES_WriteObj(struct sess *sp) ...@@ -270,41 +270,41 @@ RES_WriteObj(struct sess *sp)
/* /*
* Always remove C-E if client don't grok it * Always remove C-E if client don't grok it
*/ */
if (sp->wrk->res_mode & RES_GUNZIP) if (req->res_mode & RES_GUNZIP)
http_Unset(req->resp, H_Content_Encoding); http_Unset(req->resp, H_Content_Encoding);
/* /*
* Send HTTP protocol header, unless interior ESI object * Send HTTP protocol header, unless interior ESI object
*/ */
if (!(sp->wrk->res_mode & RES_ESI_CHILD)) if (!(req->res_mode & RES_ESI_CHILD))
sp->wrk->acct_tmp.hdrbytes += sp->wrk->acct_tmp.hdrbytes +=
http_Write(sp->wrk, sp->vsl_id, req->resp, 1); http_Write(sp->wrk, sp->vsl_id, req->resp, 1);
if (!req->wantbody) if (!req->wantbody)
sp->wrk->res_mode &= ~RES_CHUNKED; req->res_mode &= ~RES_CHUNKED;
if (sp->wrk->res_mode & RES_CHUNKED) if (req->res_mode & RES_CHUNKED)
WRW_Chunked(sp->wrk); WRW_Chunked(sp->wrk);
if (!req->wantbody) { if (!req->wantbody) {
/* This was a HEAD or conditional request */ /* This was a HEAD or conditional request */
} else if (req->obj->len == 0) { } else if (req->obj->len == 0) {
/* Nothing to do here */ /* Nothing to do here */
} else if (sp->wrk->res_mode & RES_ESI) { } else if (req->res_mode & RES_ESI) {
ESI_Deliver(sp); ESI_Deliver(sp);
} else if (sp->wrk->res_mode & RES_ESI_CHILD && req->gzip_resp) { } else if (req->res_mode & RES_ESI_CHILD && req->gzip_resp) {
ESI_DeliverChild(sp); ESI_DeliverChild(sp);
} else if (sp->wrk->res_mode & RES_ESI_CHILD && } else if (req->res_mode & RES_ESI_CHILD &&
!req->gzip_resp && req->obj->gziped) { !req->gzip_resp && req->obj->gziped) {
res_WriteGunzipObj(sp); res_WriteGunzipObj(sp);
} else if (sp->wrk->res_mode & RES_GUNZIP) { } else if (req->res_mode & RES_GUNZIP) {
res_WriteGunzipObj(sp); res_WriteGunzipObj(sp);
} else { } else {
res_WriteDirObj(sp, low, high); res_WriteDirObj(sp, low, high);
} }
if (sp->wrk->res_mode & RES_CHUNKED && if (req->res_mode & RES_CHUNKED &&
!(sp->wrk->res_mode & RES_ESI_CHILD)) !(req->res_mode & RES_ESI_CHILD))
WRW_EndChunk(sp->wrk); WRW_EndChunk(sp->wrk);
if (WRW_FlushRelease(sp->wrk) && sp->fd >= 0) if (WRW_FlushRelease(sp->wrk) && sp->fd >= 0)
...@@ -321,18 +321,18 @@ RES_StreamStart(struct sess *sp) ...@@ -321,18 +321,18 @@ RES_StreamStart(struct sess *sp)
sctx = sp->wrk->sctx; sctx = sp->wrk->sctx;
CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC); CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
AZ(sp->wrk->res_mode & RES_ESI_CHILD); AZ(sp->req->res_mode & RES_ESI_CHILD);
AN(sp->req->wantbody); AN(sp->req->wantbody);
WRW_Reserve(sp->wrk, &sp->fd); WRW_Reserve(sp->wrk, &sp->fd);
if (sp->wrk->res_mode & RES_GUNZIP) { if (sp->req->res_mode & RES_GUNZIP) {
sctx->vgz = VGZ_NewUngzip(sp->wrk, "U S -"); sctx->vgz = VGZ_NewUngzip(sp->wrk, "U S -");
AZ(VGZ_WrwInit(sctx->vgz)); AZ(VGZ_WrwInit(sctx->vgz));
http_Unset(sp->req->resp, H_Content_Encoding); http_Unset(sp->req->resp, H_Content_Encoding);
} }
if (!(sp->wrk->res_mode & RES_CHUNKED) && if (!(sp->req->res_mode & RES_CHUNKED) &&
sp->wrk->busyobj->h_content_length != NULL) sp->wrk->busyobj->h_content_length != NULL)
http_PrintfHeader(sp->wrk, sp->vsl_id, sp->req->resp, http_PrintfHeader(sp->wrk, sp->vsl_id, sp->req->resp,
"Content-Length: %s", sp->wrk->busyobj->h_content_length); "Content-Length: %s", sp->wrk->busyobj->h_content_length);
...@@ -340,7 +340,7 @@ RES_StreamStart(struct sess *sp) ...@@ -340,7 +340,7 @@ RES_StreamStart(struct sess *sp)
sp->wrk->acct_tmp.hdrbytes += sp->wrk->acct_tmp.hdrbytes +=
http_Write(sp->wrk, sp->vsl_id, sp->req->resp, 1); http_Write(sp->wrk, sp->vsl_id, sp->req->resp, 1);
if (sp->wrk->res_mode & RES_CHUNKED) if (sp->req->res_mode & RES_CHUNKED)
WRW_Chunked(sp->wrk); WRW_Chunked(sp->wrk);
} }
...@@ -367,7 +367,7 @@ RES_StreamPoll(struct worker *wrk) ...@@ -367,7 +367,7 @@ RES_StreamPoll(struct worker *wrk)
} }
l2 = st->len + l - sctx->stream_next; l2 = st->len + l - sctx->stream_next;
ptr = st->ptr + (sctx->stream_next - l); ptr = st->ptr + (sctx->stream_next - l);
if (wrk->res_mode & RES_GUNZIP) { if (wrk->sp->req->res_mode & RES_GUNZIP) {
(void)VGZ_WrwGunzip(wrk, sctx->vgz, ptr, l2); (void)VGZ_WrwGunzip(wrk, sctx->vgz, ptr, l2);
} else { } else {
(void)WRW_Write(wrk, ptr, l2); (void)WRW_Write(wrk, ptr, l2);
...@@ -375,7 +375,7 @@ RES_StreamPoll(struct worker *wrk) ...@@ -375,7 +375,7 @@ RES_StreamPoll(struct worker *wrk)
l += st->len; l += st->len;
sctx->stream_next += l2; sctx->stream_next += l2;
} }
if (!(wrk->res_mode & RES_GUNZIP)) if (!(wrk->sp->req->res_mode & RES_GUNZIP))
(void)WRW_Flush(wrk); (void)WRW_Flush(wrk);
if (wrk->busyobj->fetch_obj->objcore == NULL || if (wrk->busyobj->fetch_obj->objcore == NULL ||
...@@ -404,13 +404,13 @@ RES_StreamEnd(struct sess *sp) ...@@ -404,13 +404,13 @@ RES_StreamEnd(struct sess *sp)
sctx = sp->wrk->sctx; sctx = sp->wrk->sctx;
CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC); CHECK_OBJ_NOTNULL(sctx, STREAM_CTX_MAGIC);
if (sp->wrk->res_mode & RES_GUNZIP) { if (sp->req->res_mode & RES_GUNZIP) {
AN(sctx->vgz); AN(sctx->vgz);
VGZ_WrwFlush(sp->wrk, sctx->vgz); VGZ_WrwFlush(sp->wrk, sctx->vgz);
(void)VGZ_Destroy(&sctx->vgz, sp->vsl_id); (void)VGZ_Destroy(&sctx->vgz, sp->vsl_id);
} }
if (sp->wrk->res_mode & RES_CHUNKED && if (sp->req->res_mode & RES_CHUNKED &&
!(sp->wrk->res_mode & RES_ESI_CHILD)) !(sp->req->res_mode & RES_ESI_CHILD))
WRW_EndChunk(sp->wrk); WRW_EndChunk(sp->wrk);
if (WRW_FlushRelease(sp->wrk)) if (WRW_FlushRelease(sp->wrk))
SES_Close(sp, "remote closed"); SES_Close(sp, "remote closed");
......
...@@ -165,3 +165,4 @@ ...@@ -165,3 +165,4 @@
-e712 // 96 Loss of precision (___) (___ to ___) -e712 // 96 Loss of precision (___) (___ to ___)
-e747 // 297 Significant prototype coercion (___) ___ to ___ -e747 // 297 Significant prototype coercion (___) ___ to ___
-e840 // Use of nul character in a string literal (see: vcc_if.c) -e840 // Use of nul character in a string literal (see: vcc_if.c)
-e663 // Suspicious array to pointer conversion
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