void http_CopyReq(struct http *to, struct http *fm);
void http_CopyResp(struct http *to, struct http *fm);
void http_SetResp(struct http *to, const char *proto, const char *status, const char *response);
-void http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how);
+void http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how);
+void http_FilterHeader(struct sess *sp, unsigned how);
void http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol);
void http_PutStatus(struct worker *w, int fd, struct http *to, int status);
void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response);
static int
cnt_fetch(struct sess *sp)
{
- struct bereq *bereq;
- struct http *hp;
- char *b;
int i;
- bereq = vbe_new_bereq();
- AN(bereq);
- hp = bereq->http;
- hp->logtag = HTTP_Tx;
-
- http_GetReq(hp, sp->http);
- http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_FETCH);
- http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
- http_PrintfHeader(sp->wrk, sp->fd, hp,
- "X-Forwarded-for: %s", sp->addr);
- if (!http_GetHdr(hp, H_Host, &b)) {
- http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s",
- sp->backend->hostname);
- }
- sp->bereq = bereq;
-
+ AN(sp->bereq);
i = Fetch(sp);
vbe_free_bereq(sp->bereq);
sp->bereq = NULL;
cnt_miss(struct sess *sp)
{
+ http_FilterHeader(sp, HTTPH_R_FETCH);
VCL_miss_method(sp);
if (sp->handling == VCL_RET_ERROR) {
sp->obj->cacheable = 0;
HSH_Deref(sp->obj);
sp->obj = NULL;
sp->step = STP_PASS;
+ vbe_free_bereq(sp->bereq);
+ sp->bereq = NULL;
return (0);
}
if (sp->handling == VCL_RET_FETCH) {
AZ(sp->obj);
+ http_FilterHeader(sp, HTTPH_R_PASS);
+
VCL_pass_method(sp);
if (sp->handling == VCL_RET_ERROR) {
sp->step = STP_ERROR;
static int
cnt_pipe(struct sess *sp)
{
- struct bereq *bereq;
- struct http *hp;
- char *b;
sp->wrk->acct.pipe++;
-
- bereq = vbe_new_bereq();
- XXXAN(bereq);
- hp = bereq->http;
- hp->logtag = HTTP_Tx;
-
- http_CopyReq(hp, sp->http);
- http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_PIPE);
- http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
- http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Forwarded-for: %s", sp->addr);
-
- /* XXX: does this belong in VCL ? */
- if (!http_GetHdr(hp, H_Host, &b)) {
- http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s",
- sp->backend->hostname);
- }
+ http_FilterHeader(sp, HTTPH_R_PIPE);
VCL_pipe_method(sp);
if (sp->handling == VCL_RET_ERROR)
INCOMPL();
- sp->bereq = bereq;
PipeSession(sp);
sp->step = STP_DONE;
return (0);
hp2->logtag = HTTP_Obj;
http_CopyResp(hp2, hp);
- http_FilterHeader(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS);
+ http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS);
http_CopyHome(sp->wrk, sp->fd, hp2);
if (body) {
/*--------------------------------------------------------------------*/
void
-http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how)
+http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how)
{
unsigned u;
}
}
+/*--------------------------------------------------------------------*/
+
+void
+http_FilterHeader(struct sess *sp, unsigned how)
+{
+ struct bereq *bereq;
+ struct http *hp;
+ char *b;
+
+ bereq = vbe_new_bereq();
+ AN(bereq);
+ hp = bereq->http;
+ hp->logtag = HTTP_Tx;
+
+ http_GetReq(hp, sp->http);
+ http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
+ http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
+ http_PrintfHeader(sp->wrk, sp->fd, hp,
+ "X-Forwarded-for: %s", sp->addr);
+ if (!http_GetHdr(hp, H_Host, &b)) {
+ http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s",
+ sp->backend->hostname);
+ }
+ sp->bereq = bereq;
+}
+
/*--------------------------------------------------------------------
* This function copies any header fields which reference foreign
* storage into our own WS.
http_ClrHeader(sp->http);
sp->http->logtag = HTTP_Tx;
http_CopyResp(sp->http, &sp->obj->http);
- http_FilterHeader(sp->wrk, sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
+ http_FilterFields(sp->wrk, sp->fd, sp->http, &sp->obj->http,
+ HTTPH_A_DELIVER);
if (sp->xid != sp->obj->xid)
http_PrintfHeader(sp->wrk, sp->fd, sp->http,
"X-Varnish: %u %u", sp->xid, sp->obj->xid);