r572 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jul 31 09:26:25 CEST 2006
Author: phk
Date: 2006-07-31 09:26:25 +0200 (Mon, 31 Jul 2006)
New Revision: 572
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_http.c
trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Introduce http_SetHeader() for setting a http header to a const string,
no need to waste time printf'ing in this case, and no need to waste workspace.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-07-31 07:13:45 UTC (rev 571)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-07-31 07:26:25 UTC (rev 572)
@@ -328,6 +328,7 @@
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);
Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c 2006-07-31 07:13:45 UTC (rev 571)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c 2006-07-31 07:26:25 UTC (rev 572)
@@ -484,7 +484,9 @@
AZ(event_add(&hp->ev, NULL)); /* XXX: timeout */
}
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Copy HTTP headers into malloc'ed space.
+ */
void
http_CopyHttp(struct http *to, struct http *fm)
@@ -615,6 +617,19 @@
/*--------------------------------------------------------------------*/
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, ...)
{
va_list ap;
Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c 2006-07-31 07:13:45 UTC (rev 571)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c 2006-07-31 07:26:25 UTC (rev 572)
@@ -84,21 +84,16 @@
sp->http->f = sp->http->v;
- sp->http->nhd = HTTP_HDR_PROTO;
- http_PrintfHeader(sp->fd, sp->http, "HTTP/1.1");
+ 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_STATUS;
- http_PrintfHeader(sp->fd, sp->http, "304");
-
- sp->http->nhd = HTTP_HDR_RESPONSE;
- http_PrintfHeader(sp->fd, sp->http, "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 @@
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);
More information about the varnish-commit
mailing list