Commit d2cadf1a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@572 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent f5e87c21
......@@ -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);
......
......@@ -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, ...)
{
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment