From: phk Date: Mon, 31 Jul 2006 20:38:46 +0000 (+0000) Subject: Add a http_SetResp() function for constructing HTTP responses (like 304). X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2ec1656a6162364e71b7ab4c533fddb12008678;p=varnish Add a http_SetResp() function for constructing HTTP responses (like 304). Eliminate the header index from http_SetHeader() which is no unused. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@576 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index f6e04a09..38724939 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -327,9 +327,10 @@ unsigned http_Write(struct worker *w, struct http *hp, int resp); void http_GetReq(int fd, struct http *to, struct http *fm); void http_CopyReq(int fd, struct http *to, struct http *fm); void http_CopyResp(int fd, struct http *to, struct http *fm); +void http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response); void http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how); void http_PrintfHeader(int fd, struct http *to, const char *fmt, ...); -void http_SetHeader(int fd, struct http *to, unsigned n, const char *hdr); +void http_SetHeader(int fd, struct http *to, const char *hdr); int http_IsHdr(struct http_hdr *hh, char *hdr); void http_Setup(struct http *ht, void *space, unsigned len); int http_GetHdr(struct http *hp, const char *hdr, char **ptr); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 012425c1..8f319b41 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -580,6 +580,15 @@ http_CopyResp(int fd, struct http *to, struct http *fm) http_copyh(fd, to, fm, HTTP_HDR_RESPONSE, SLT_Response); } +void +http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response) +{ + CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); + http_seth(fd, to, HTTP_HDR_PROTO, SLT_Protocol, proto); + http_seth(fd, to, HTTP_HDR_STATUS, SLT_Status, status); + http_seth(fd, to, HTTP_HDR_RESPONSE, SLT_Response, response); +} + static void http_copyheader(int fd, struct http *to, struct http *fm, unsigned n) { @@ -620,14 +629,14 @@ http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how) /*--------------------------------------------------------------------*/ void -http_SetHeader(int fd, struct http *to, unsigned n, const char *hdr) +http_SetHeader(int fd, struct http *to, const char *hdr) { - if (n == 0) - n = to->nhd++; - to->hd[n].b = (void*)(uintptr_t)hdr; - to->hd[n].e = strchr(hdr, '\0'); - VSLHT(fd, to, n); + to->hd[to->nhd].b = (void*)(uintptr_t)hdr; + to->hd[to->nhd].e = strchr(hdr, '\0'); + assert(to->hd[to->nhd].e != NULL); + VSLHT(fd, to, to->nhd); + to->nhd++; } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 0430bf45..c9d049f0 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -84,16 +84,14 @@ res_do_304(struct sess *sp, char *p) sp->http->f = sp->http->v; - http_SetHeader(sp->fd, sp->http, HTTP_HDR_PROTO, "HTTP/1.1"); - http_SetHeader(sp->fd, sp->http, HTTP_HDR_STATUS, "304"); - http_SetHeader(sp->fd, sp->http, HTTP_HDR_RESPONSE, "Not Modified"); + http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified"); sp->http->nhd = HTTP_HDR_FIRST; - http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish"); + http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish"); http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->fd, sp->http, "Last-Modified: %s", p); if (sp->doclose != NULL) - http_SetHeader(sp->fd, sp->http, 0, "Connection: close"); + http_SetHeader(sp->fd, sp->http, "Connection: close"); WRK_Reset(sp->wrk, &sp->fd); http_Write(sp->wrk, sp->http, 1); if (WRK_Flush(sp->wrk)) @@ -150,9 +148,9 @@ RES_WriteObj(struct sess *sp) http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->fd, sp->http, "Age: %u", sp->obj->age + sp->t_req - sp->obj->entered); - http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish"); + http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish"); if (sp->doclose != NULL) - http_SetHeader(sp->fd, sp->http, 0, "Connection: close"); + http_SetHeader(sp->fd, sp->http, "Connection: close"); WRK_Reset(sp->wrk, &sp->fd); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);