Commit 89870e0b authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Be more RFC2616 compliant, by keeping Date header as given from the

backend. Set it on the object if missing.

Previously we would add an explicit Date header on each response with
the time and date of the response, overwriting any Date header on the
object that came from the backend.

Now we will add a Date header if the backend didn't supply one just
before vcl_backend_response() is run, and not add any Date headers for
the replies.

This change means Date headers sent by Varnish is approximately the
time and date this object was generated by the backend, and not the
current date and time.
parent 426474c0
......@@ -249,6 +249,8 @@ static enum fetch_step
vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
{
int i, do_ims;
double now;
char time_str[VTIM_FORMAT_SIZE];
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
......@@ -292,7 +294,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
VSC_C_main->backend_retry++;
i = V1F_fetch_hdr(wrk, bo, bo->req);
}
VSLb_ts_busyobj(bo, "Beresp", W_TIM_real(wrk));
now = W_TIM_real(wrk);
VSLb_ts_busyobj(bo, "Beresp", now);
if (i) {
AZ(bo->vbc);
......@@ -302,6 +305,22 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
AN(bo->vbc);
http_VSL_log(bo->beresp);
if (!http_GetHdr(bo->beresp, H_Date, NULL)) {
/*
* RFC 2616 14.18 Date: The Date general-header field
* represents the date and time at which the message was
* originated, having the same semantics as orig-date in
* RFC 822. ... A received message that does not have a
* Date header field MUST be assigned one by the recipient
* if the message will be cached by that recipient or
* gatewayed via a protocol which requires a Date.
*
* 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);
}
/*
* These two headers can be spread over multiple actual headers
* and we rely on their content outside of VCL, so collect them
......
......@@ -87,7 +87,6 @@ DOT deliver:deliver:s -> DONE [style=bold,color=blue]
static enum req_fsm_nxt
cnt_deliver(struct worker *wrk, struct req *req)
{
char time_str[30];
double now;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
......@@ -110,10 +109,6 @@ cnt_deliver(struct worker *wrk, struct req *req)
http_ClrHeader(req->resp);
http_FilterResp(req->obj->http, req->resp, 0);
http_Unset(req->resp, H_Date);
VTIM_format(now, time_str);
http_PrintfHeader(req->resp, "Date: %s", time_str);
if (req->wrk->stats.cache_hit)
http_PrintfHeader(req->resp,
"X-Varnish: %u %u", req->vsl->wid & VSL_IDENTMASK,
......
......@@ -25,6 +25,8 @@ varnish v1 \
sub vcl_backend_response {
set beresp.do_stream = false;
set beresp.storage_hint = "invalid";
# Unset Date header to not change the object sizes
unset beresp.http.Date;
}
} -start
......
......@@ -17,6 +17,8 @@ varnish v1 \
sub vcl_backend_response {
set beresp.do_stream = false;
set beresp.storage_hint = "s0";
# Unset Date header to not change the object sizes
unset beresp.http.Date;
}
} -start
......
......@@ -22,6 +22,8 @@ varnish v1 -arg "-p nuke_limit=0 -p shortlived=0" \
-arg "-smalloc,1m" -vcl+backend {
sub vcl_backend_response {
set beresp.do_stream = false;
# Unset Date header to not change the object sizes
unset beresp.http.Date;
}
} -start
......
......@@ -16,6 +16,8 @@ varnish v1 \
sub vcl_backend_response {
set beresp.do_stream = false;
set beresp.storage_hint = "Transient";
# Unset Date header to not change the object sizes
unset beresp.http.Date;
}
} -start
......
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