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