Commit a9dc4a2a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Extract the two bits of information we need from the unadultered beresp,

rather than saving the entire thing.

This also moves a bit more of the fetch-policy/standards-compliance into
rfc2616.c
parent e4a0af76
...@@ -273,7 +273,6 @@ struct worker { ...@@ -273,7 +273,6 @@ struct worker {
struct ws ws[1]; struct ws ws[1];
struct http *http[3]; struct http *http[3];
struct http *bereq; struct http *bereq;
struct http *beresp1;
struct http *beresp; struct http *beresp;
struct http *resp; struct http *resp;
...@@ -294,6 +293,8 @@ struct worker { ...@@ -294,6 +293,8 @@ struct worker {
unsigned is_gzip; unsigned is_gzip;
unsigned do_gunzip; unsigned do_gunzip;
unsigned is_gunzip; unsigned is_gunzip;
unsigned do_close;
char *h_content_length;
/* ESI stuff */ /* ESI stuff */
struct vep_state *vep; struct vep_state *vep;
...@@ -651,7 +652,7 @@ int EXP_NukeOne(const struct sess *sp, struct lru *lru); ...@@ -651,7 +652,7 @@ int EXP_NukeOne(const struct sess *sp, struct lru *lru);
/* cache_fetch.c */ /* cache_fetch.c */
struct storage *FetchStorage(const struct sess *sp, ssize_t sz); struct storage *FetchStorage(const struct sess *sp, ssize_t sz);
int FetchHdr(struct sess *sp); int FetchHdr(struct sess *sp);
int FetchBody(struct sess *sp, const struct http *hp); int FetchBody(struct sess *sp);
int FetchReqBody(struct sess *sp); int FetchReqBody(struct sess *sp);
void Fetch_Init(void); void Fetch_Init(void);
......
...@@ -229,7 +229,6 @@ cnt_deliver(struct sess *sp) ...@@ -229,7 +229,6 @@ cnt_deliver(struct sess *sp)
sp->director = NULL; sp->director = NULL;
sp->wrk->bereq = NULL; sp->wrk->bereq = NULL;
sp->wrk->beresp = NULL; sp->wrk->beresp = NULL;
sp->wrk->beresp1 = NULL;
sp->wrk->resp = NULL; sp->wrk->resp = NULL;
sp->step = STP_RECV; sp->step = STP_RECV;
return (0); return (0);
...@@ -475,6 +474,8 @@ cnt_fetch(struct sess *sp) ...@@ -475,6 +474,8 @@ cnt_fetch(struct sess *sp)
AN(sp->director); AN(sp->director);
AZ(sp->vbc); AZ(sp->vbc);
AZ(sp->wrk->h_content_length);
AZ(sp->wrk->do_close);
/* sp->wrk->http[0] is (still) bereq */ /* sp->wrk->http[0] is (still) bereq */
sp->wrk->beresp = sp->wrk->http[1]; sp->wrk->beresp = sp->wrk->http[1];
...@@ -500,11 +501,11 @@ cnt_fetch(struct sess *sp) ...@@ -500,11 +501,11 @@ cnt_fetch(struct sess *sp)
http_CollectHdr(sp->wrk->beresp, H_Vary); http_CollectHdr(sp->wrk->beresp, H_Vary);
/* /*
* Save a copy before it might get mangled in VCL. When it comes to * Figure out how the fetch is supposed to happen, before the
* dealing with the body, we want to see the unadultered headers. * headers are adultered by VCL
*/ * Also sets other sp->wrk variables
sp->wrk->beresp1 = sp->wrk->http[2]; */
*sp->wrk->beresp1 = *sp->wrk->beresp; sp->wrk->body_status = RFC2616_Body(sp);
if (i) { if (i) {
if (sp->objcore != NULL) { if (sp->objcore != NULL) {
...@@ -513,9 +514,10 @@ cnt_fetch(struct sess *sp) ...@@ -513,9 +514,10 @@ cnt_fetch(struct sess *sp)
sp->objcore = NULL; sp->objcore = NULL;
} }
AZ(sp->obj); AZ(sp->obj);
sp->wrk->do_close = 0;
sp->wrk->h_content_length = NULL;
sp->wrk->bereq = NULL; sp->wrk->bereq = NULL;
sp->wrk->beresp = NULL; sp->wrk->beresp = NULL;
sp->wrk->beresp1 = NULL;
sp->err_code = 503; sp->err_code = 503;
sp->step = STP_ERROR; sp->step = STP_ERROR;
return (0); return (0);
...@@ -555,7 +557,6 @@ cnt_fetch(struct sess *sp) ...@@ -555,7 +557,6 @@ cnt_fetch(struct sess *sp)
sp->wrk->do_esi = 0; sp->wrk->do_esi = 0;
sp->wrk->body_status = RFC2616_Body(sp);
AZ(sp->wrk->storage_hint); AZ(sp->wrk->storage_hint);
...@@ -698,11 +699,13 @@ cnt_fetch(struct sess *sp) ...@@ -698,11 +699,13 @@ cnt_fetch(struct sess *sp)
sp->obj->last_modified = sp->wrk->entered; sp->obj->last_modified = sp->wrk->entered;
/* Use unmodified headers*/ /* Use unmodified headers*/
i = FetchBody(sp, sp->wrk->beresp1); i = FetchBody(sp);
sp->wrk->do_close = 0;
sp->wrk->h_content_length = NULL;
sp->wrk->bereq = NULL; sp->wrk->bereq = NULL;
sp->wrk->beresp = NULL; sp->wrk->beresp = NULL;
sp->wrk->beresp1 = NULL;
sp->wrk->vfp = NULL; sp->wrk->vfp = NULL;
AZ(sp->wrk->wfd); AZ(sp->wrk->wfd);
AZ(sp->vbc); AZ(sp->vbc);
......
...@@ -482,9 +482,8 @@ FetchHdr(struct sess *sp) ...@@ -482,9 +482,8 @@ FetchHdr(struct sess *sp)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
int int
FetchBody(struct sess *sp, const struct http *hp) FetchBody(struct sess *sp)
{ {
char *b;
int cls; int cls;
struct storage *st; struct storage *st;
int mklen; int mklen;
...@@ -517,8 +516,8 @@ FetchBody(struct sess *sp, const struct http *hp) ...@@ -517,8 +516,8 @@ FetchBody(struct sess *sp, const struct http *hp)
mklen = 1; mklen = 1;
break; break;
case BS_LENGTH: case BS_LENGTH:
AN(http_GetHdr(hp, H_Content_Length, &b)); cls = fetch_straight(sp, sp->wrk->htc,
cls = fetch_straight(sp, sp->wrk->htc, b); sp->wrk->h_content_length);
mklen = 1; mklen = 1;
break; break;
case BS_CHUNKED: case BS_CHUNKED:
...@@ -555,11 +554,7 @@ FetchBody(struct sess *sp, const struct http *hp) ...@@ -555,11 +554,7 @@ FetchBody(struct sess *sp, const struct http *hp)
return (__LINE__); return (__LINE__);
} }
if (cls == 0 && http_HdrIs(hp, H_Connection, "close")) if (cls == 0 && sp->wrk->do_close)
cls = 1;
if (cls == 0 && hp->protover < 1.1 &&
!http_HdrIs(hp, H_Connection, "keep-alive"))
cls = 1; cls = 1;
if (cls < 0) { if (cls < 0) {
...@@ -593,9 +588,6 @@ FetchBody(struct sess *sp, const struct http *hp) ...@@ -593,9 +588,6 @@ FetchBody(struct sess *sp, const struct http *hp)
"Content-Length: %u", sp->obj->len); "Content-Length: %u", sp->obj->len);
} }
if (http_HdrIs(hp, H_Connection, "close"))
cls = 1;
if (cls) if (cls)
VDI_CloseFd(sp); VDI_CloseFd(sp);
else else
......
...@@ -179,13 +179,11 @@ wrk_thread_real(struct wq *qp, unsigned shm_workspace, unsigned sess_workspace, ...@@ -179,13 +179,11 @@ wrk_thread_real(struct wq *qp, unsigned shm_workspace, unsigned sess_workspace,
w->lastused = NAN; w->lastused = NAN;
WS_Reset(w->ws, NULL); WS_Reset(w->ws, NULL);
w->bereq = NULL; w->bereq = NULL;
w->beresp1 = NULL;
w->beresp = NULL; w->beresp = NULL;
w->resp = NULL; w->resp = NULL;
w->storage_hint = NULL; w->storage_hint = NULL;
w->wrq->func(w, w->wrq->priv); w->wrq->func(w, w->wrq->priv);
AZ(w->bereq); AZ(w->bereq);
AZ(w->beresp1);
AZ(w->beresp); AZ(w->beresp);
AZ(w->resp); AZ(w->resp);
WS_Assert(w->ws); WS_Assert(w->ws);
......
...@@ -160,7 +160,7 @@ RFC2616_Ttl(const struct sess *sp) ...@@ -160,7 +160,7 @@ RFC2616_Ttl(const struct sess *sp)
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Body existence and fetch method * Body existence, fetch method and close policy.
*/ */
enum body_status enum body_status
...@@ -169,7 +169,14 @@ RFC2616_Body(const struct sess *sp) ...@@ -169,7 +169,14 @@ RFC2616_Body(const struct sess *sp)
struct http *hp; struct http *hp;
char *b; char *b;
hp = sp->wrk->beresp1; hp = sp->wrk->beresp;
if (hp->protover < 1.1 && !http_HdrIs(hp, H_Connection, "keep-alive"))
sp->wrk->do_close = 1;
else if (http_HdrIs(hp, H_Connection, "close"))
sp->wrk->do_close = 1;
else
sp->wrk->do_close = 0;
if (!strcasecmp(http_GetReq(sp->wrk->bereq), "head")) { if (!strcasecmp(http_GetReq(sp->wrk->bereq), "head")) {
/* /*
...@@ -218,7 +225,7 @@ RFC2616_Body(const struct sess *sp) ...@@ -218,7 +225,7 @@ RFC2616_Body(const struct sess *sp)
return (BS_ERROR); return (BS_ERROR);
} }
if (http_GetHdr(hp, H_Content_Length, &b)) { if (http_GetHdr(hp, H_Content_Length, &sp->wrk->h_content_length)) {
sp->wrk->stats.fetch_length++; sp->wrk->stats.fetch_length++;
return (BS_LENGTH); return (BS_LENGTH);
} }
......
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