Commit 65519e9b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a http_SetResp() function for constructing HTTP responses (like 304).

Eliminate the header index from http_SetHeader() which is no unused.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@576 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e698fecb
......@@ -327,9 +327,10 @@ unsigned http_Write(struct worker *w, struct http *hp, int resp);
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);
......
......@@ -580,6 +580,15 @@ http_CopyResp(int fd, struct http *to, struct http *fm)
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)
{
......@@ -620,14 +629,14 @@ 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)
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++;
}
/*--------------------------------------------------------------------*/
......
......@@ -84,16 +84,14 @@ res_do_304(struct sess *sp, char *p)
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))
......@@ -150,9 +148,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_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);
......
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