From bcefad3e88451d0e69379332932291af2eee7691 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 23 Sep 2007 13:46:43 +0000 Subject: [PATCH] Fix another cornercase that fell out as part of the pass->fetch rewrite: If we pass a HEAD request, we should not rewrite it to GET and not expect a body either. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1997 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 1 + varnish-cache/bin/varnishd/cache_fetch.c | 7 +++++-- varnish-cache/bin/varnishd/cache_http.c | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index a840a144..be9a8dd0 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -463,6 +463,7 @@ void http_Setup(struct http *ht, void *space, unsigned len); int http_GetHdr(struct http *hp, const char *hdr, char **ptr); int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr); int http_GetStatus(struct http *hp); +const char *http_GetReq(struct http *hp); const char *http_GetProto(struct http *hp); int http_HdrIs(struct http *hp, const char *hdr, const char *val); int http_GetTail(struct http *hp, unsigned len, char **b, char **e); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 9e6d8ba8..0dd8c4b5 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -263,7 +263,7 @@ Fetch(struct sess *sp) struct http *hp, *hp2; struct storage *st; struct bereq *bereq; - int len, mklen; + int len, mklen, is_get; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); @@ -272,6 +272,7 @@ Fetch(struct sess *sp) w = sp->wrk; bereq = sp->bereq; hp = bereq->http; + is_get = !strcasecmp(http_GetReq(hp), "get"); sp->obj->xid = sp->xid; @@ -341,7 +342,9 @@ Fetch(struct sess *sp) /* Determine if we have a body or not */ cls = 0; mklen = 0; - if (http_GetHdr(hp, H_Content_Length, &b)) { + if (!is_get) { + /* nothing */ + } else if (http_GetHdr(hp, H_Content_Length, &b)) { cls = fetch_straight(sp, vc->fd, hp, b); mklen = 1; } else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked")) { diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 33368194..e5c99e0b 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -388,6 +388,13 @@ http_GetProto(struct http *hp) return (hp->hd[HTTP_HDR_PROTO].b); } +const char * +http_GetReq(struct http *hp) +{ + AN(hp->hd[HTTP_HDR_REQ].b); + return (hp->hd[HTTP_HDR_REQ].b); +} + /*-------------------------------------------------------------------- * Dissect the headers of the HTTP protocol message. * Detect conditionals (headers which start with '^[Ii][Ff]-') @@ -802,7 +809,8 @@ http_FilterHeader(struct sess *sp, unsigned how) hp = bereq->http; hp->logtag = HTTP_Tx; - http_copyreq(hp, sp->http, how == HTTPH_R_PIPE); + http_copyreq(hp, sp->http, + (how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS)); 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, -- 2.39.5