void http_GetReq(int fd, struct http *to, struct http *fm);
void http_CopyReq(int fd, struct http *to, struct http *fm);
void http_CopyResp(int fd, struct http *to, struct http *fm);
+void http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response);
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);
+void http_SetHeader(int fd, struct http *to, 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);
http_copyh(fd, to, fm, HTTP_HDR_RESPONSE, SLT_Response);
}
+void
+http_SetResp(int fd, struct http *to, const char *proto, const char *status, const char *response)
+{
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+ http_seth(fd, to, HTTP_HDR_PROTO, SLT_Protocol, proto);
+ http_seth(fd, to, HTTP_HDR_STATUS, SLT_Status, status);
+ http_seth(fd, to, HTTP_HDR_RESPONSE, SLT_Response, response);
+}
+
static void
http_copyheader(int fd, struct http *to, struct http *fm, unsigned n)
{
/*--------------------------------------------------------------------*/
void
-http_SetHeader(int fd, struct http *to, unsigned n, const char *hdr)
+http_SetHeader(int fd, struct http *to, const char *hdr)
{
- if (n == 0)
- n = to->nhd++;
- to->hd[n].b = (void*)(uintptr_t)hdr;
- to->hd[n].e = strchr(hdr, '\0');
- VSLHT(fd, to, n);
+ to->hd[to->nhd].b = (void*)(uintptr_t)hdr;
+ to->hd[to->nhd].e = strchr(hdr, '\0');
+ assert(to->hd[to->nhd].e != NULL);
+ VSLHT(fd, to, to->nhd);
+ to->nhd++;
}
/*--------------------------------------------------------------------*/
sp->http->f = sp->http->v;
- 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");
+ http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
sp->http->nhd = HTTP_HDR_FIRST;
- http_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish");
+ 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->doclose != NULL)
- http_SetHeader(sp->fd, sp->http, 0, "Connection: close");
+ http_SetHeader(sp->fd, sp->http, "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_SetHeader(sp->fd, sp->http, 0, "Via: 1.1 varnish");
+ http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
if (sp->doclose != NULL)
- http_SetHeader(sp->fd, sp->http, 0, "Connection: close");
+ http_SetHeader(sp->fd, sp->http, "Connection: close");
WRK_Reset(sp->wrk, &sp->fd);
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);