]> err.no Git - varnish/commitdiff
Introduce http_SetHeader() for setting a http header to a const string,
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 31 Jul 2006 07:26:25 +0000 (07:26 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 31 Jul 2006 07:26:25 +0000 (07:26 +0000)
no need to waste time printf'ing in this case, and no need to waste workspace.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@572 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 1d7a0b2e84fa6587174bf99eacc9db1c6a4c6902..97c7658aee886b67e9397712d68618e499f3d511 100644 (file)
@@ -328,6 +328,7 @@ void http_CopyReq(int fd, struct http *to, struct http *fm);
 void http_CopyResp(int fd, struct http *to, struct http *fm);
 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);
 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 e1beeca05b9aeb3d05503cd7d7723ee4f534ed0c..c9240f70527c5b9a4f359f6f13b6501092a7d25c 100644 (file)
@@ -484,7 +484,9 @@ http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *f
        AZ(event_add(&hp->ev, NULL));      /* XXX: timeout */
 }
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Copy HTTP headers into malloc'ed space.
+ */
 
 void
 http_CopyHttp(struct http *to, struct http *fm)
@@ -614,6 +616,19 @@ 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)
+{
+
+       if (n == 0)
+               n = to->nhd++;
+       to->hd[n].b = (void*)(uintptr_t)hdr;
+       to->hd[n].e = strchr(hdr, '\0');
+       VSLH(SLT_TxHeader, fd, to, n);
+}
+
+/*--------------------------------------------------------------------*/
+
 void
 http_PrintfHeader(int fd, struct http *to, const char *fmt, ...)
 {
index 5311ddf5f4f7736742e24cb2ac6c8c012f6146cf..0430bf4516d780d6df6906e835e7f642dcfb53ac 100644 (file)
@@ -84,21 +84,16 @@ res_do_304(struct sess *sp, char *p)
 
        sp->http->f = sp->http->v;
 
-       sp->http->nhd = HTTP_HDR_PROTO;
-       http_PrintfHeader(sp->fd, sp->http, "HTTP/1.1");
-
-       sp->http->nhd = HTTP_HDR_STATUS;
-       http_PrintfHeader(sp->fd, sp->http, "304");
-
-       sp->http->nhd = HTTP_HDR_RESPONSE;
-       http_PrintfHeader(sp->fd, sp->http, "Not Modified");
+       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");
 
        sp->http->nhd = HTTP_HDR_FIRST;
+       http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish");
        http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
-       http_PrintfHeader(sp->fd, sp->http, "Via: 1.1 varnish");
        http_PrintfHeader(sp->fd, sp->http, "Last-Modified: %s", p);
        if (sp->doclose != NULL)
-               http_PrintfHeader(sp->fd, sp->http, "Connection: close");
+               http_SetHeader(sp->fd, sp->http, 0, "Connection: close");
        WRK_Reset(sp->wrk, &sp->fd);
        http_Write(sp->wrk, sp->http, 1);
        if (WRK_Flush(sp->wrk))
@@ -155,9 +150,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_PrintfHeader(sp->fd, sp->http, "Via: 1.1 varnish");
+       http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish");
        if (sp->doclose != NULL)
-               http_PrintfHeader(sp->fd, sp->http, "Connection: close");
+               http_SetHeader(sp->fd, sp->http, 0, "Connection: close");
        WRK_Reset(sp->wrk, &sp->fd);
        sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);