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

Add a dedicated HTTP function to add a header with a timestamp,

to avoid some pointless double-buffering.
parent 5fe64d62
......@@ -830,6 +830,7 @@ int HTTP_Decode(struct http *to, const uint8_t *fm);
void http_ForceHeader(struct http *to, const char *hdr, const char *val);
void http_PrintfHeader(struct http *to, const char *fmt, ...)
__printflike(2, 3);
void http_TimeHeader(struct http *to, const char *fmt, double now);
void http_SetHeader(struct http *to, const char *hdr);
void http_SetH(const struct http *to, unsigned n, const char *fm);
void http_ForceField(const struct http *to, unsigned n, const char *t);
......
......@@ -262,7 +262,6 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
{
int i, do_ims = 0;
double now;
char time_str[VTIM_FORMAT_SIZE];
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
......@@ -313,8 +312,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
*
* If we didn't get a Date header, we assign one here.
*/
VTIM_format(now, time_str);
http_PrintfHeader(bo->beresp, "Date: %s", time_str);
http_TimeHeader(bo->beresp, "Date: ", now);
}
/*
......@@ -771,7 +769,6 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
ssize_t l, ll, o;
double now;
uint8_t *ptr;
char time_str[VTIM_FORMAT_SIZE];
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
......@@ -790,8 +787,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
http_PutResponse(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
VTIM_format(now, time_str);
http_PrintfHeader(bo->beresp, "Date: %s", time_str);
http_TimeHeader(bo->beresp, "Date: ", now);
http_SetHeader(bo->beresp, "Server: Varnish");
bo->fetch_objcore->exp.t_origin = bo->t_prev;
......
......@@ -38,6 +38,7 @@
#include "vend.h"
#include "vct.h"
#include "vtim.h"
#define HTTPH(a, b, c) char b[] = "*" a ":";
#include "tbl/http_headers.h"
......@@ -1112,6 +1113,27 @@ http_PrintfHeader(struct http *to, const char *fmt, ...)
to->nhd++;
}
void
http_TimeHeader(struct http *to, const char *fmt, double now)
{
char *p;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
p = WS_Alloc(to->ws, strlen(fmt) + VTIM_FORMAT_SIZE);
if (p == NULL) {
http_fail(to);
VSLb(to->vsl, SLT_LostHeader, "%s", fmt);
return;
}
strcpy(p, fmt);
VTIM_format(now, strchr(p, '\0'));
to->hd[to->nhd].b = p;
to->hd[to->nhd].e = strchr(p, '\0');
to->hdf[to->nhd] = 0;
http_VSLH(to, to->nhd);
to->nhd++;
}
/*--------------------------------------------------------------------*/
void
......
......@@ -171,7 +171,6 @@ cnt_deliver(struct worker *wrk, struct req *req)
static enum req_fsm_nxt
cnt_synth(struct worker *wrk, struct req *req)
{
char date[40];
struct http *h;
double now;
......@@ -189,8 +188,7 @@ cnt_synth(struct worker *wrk, struct req *req)
HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
h = req->resp;
VTIM_format(now, date);
http_PrintfHeader(h, "Date: %s", date);
http_TimeHeader(h, "Date: ", now);
http_SetHeader(h, "Server: Varnish");
http_PrintfHeader(req->resp, "X-Varnish: %u", VXID(req->vsl->wid));
http_PutResponse(h, "HTTP/1.1", req->err_code, req->err_reason);
......
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