* The actual headers to reply with are built later on over in
* cache_response.c
*/
- sp->http->f = sp->http->v;
- sp->http->nhd = HTTP_HDR_FIRST;
+ http_ClrHeader(sp->http);
sp->http->objlog = 1; /* log as SLT_ObjHeader */
http_CopyResp(sp->fd, sp->http, vc->http);
http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_INS);
cls = 0;
sp->http->objlog = 0;
http_CopyHttp(&sp->obj->http, sp->http);
- sp->http->f = sp->http->v;
if (http_GetHdr(vc->http, H_Connection, &b) && !strcasecmp(b, "close"))
cls = 1;
/*--------------------------------------------------------------------*/
+void
+http_ClrHeader(struct http *to)
+{
+
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+ to->f = to->v;
+ to->nhd = HTTP_HDR_FIRST;
+ memset(to->hd, 0, sizeof to->hd);
+}
+
+/*--------------------------------------------------------------------*/
+
void
http_SetHeader(int fd, struct http *to, const char *hdr)
{
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
to->hd[to->nhd].b = (void*)(uintptr_t)hdr;
to->hd[to->nhd].e = strchr(hdr, '\0');
assert(to->hd[to->nhd].e != NULL);
va_list ap;
unsigned l, n;
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
va_start(ap, fmt);
l = to->e - to->f;
n = vsnprintf(to->f, l, fmt, ap);
res_do_304(struct sess *sp, char *p)
{
- VSL(SLT_Status, sp->fd, "%u", 304);
VSL(SLT_Length, sp->fd, "%u", 0);
- sp->http->f = sp->http->v;
-
+ http_ClrHeader(sp->http);
http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
-
- sp->http->nhd = HTTP_HDR_FIRST;
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->obj->response == 200 && sp->http->conds && res_do_conds(sp))
return;
- VSL(SLT_Status, sp->fd, "%u", sp->obj->response);
VSL(SLT_Length, sp->fd, "%u", sp->obj->len);
- sp->http->f = sp->http->v;
- sp->http->nhd = HTTP_HDR_FIRST;
+ http_ClrHeader(sp->http);
http_CopyResp(sp->fd, sp->http, &sp->obj->http);
http_FilterHeader(sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
if (sp->xid != sp->obj->xid)
- http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u %u", sp->xid, sp->obj->xid);
+ http_PrintfHeader(sp->fd, sp->http,
+ "X-Varnish: %u %u", sp->xid, sp->obj->xid);
else
http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->fd, sp->http, "Age: %u",
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
/* XXX: conditional request handling */
- if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET")) {
+ if (sp->wantbody) {
TAILQ_FOREACH(st, &sp->obj->store, list) {
assert(st->stevedore != NULL);
u += st->len;