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);
AZ(event_add(&hp->ev, NULL)); /* XXX: timeout */
}
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Copy HTTP headers into malloc'ed space.
+ */
void
http_CopyHttp(struct http *to, struct http *fm)
/*--------------------------------------------------------------------*/
+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, ...)
{
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))
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);