]> err.no Git - varnish/commitdiff
Add a http_SetResp() function for constructing HTTP responses (like 304).
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 31 Jul 2006 20:38:46 +0000 (20:38 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 31 Jul 2006 20:38:46 +0000 (20:38 +0000)
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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/cache_response.c

index f6e04a09e01b523f918a04a6e49710c9c89603ed..3872493932e6554055610fc01c71ea266a73a39b 100644 (file)
@@ -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);
index 012425c1d28bcc435eeb67bc79ab0e339b7d0f1e..8f319b414ff85cf930e2395f1273f834e99e2344 100644 (file)
@@ -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++;
 }
 
 /*--------------------------------------------------------------------*/
index 0430bf4516d780d6df6906e835e7f642dcfb53ac..c9d049f0f86d4db534555d7ef114a6e5e8d5db5c 100644 (file)
@@ -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);