Commit 8fb35335 authored by AlveElde's avatar AlveElde Committed by Poul-Henning Kamp

varnishtest: txresp Date header by default

This commit prepares varnishtest for a change to Varnish revalidations,
where the Last-Modified header must be at least one second older than
the Date header for Varnish to send an If-Modified-Since header.

Any explicitly defined Date header will override the default, and
the Date header can be omitted with -nodate.
parent ae29a70d
......@@ -3,7 +3,7 @@ varnishtest "Check that a pass transaction works"
server s1 {
rxreq
expect req.proto == HTTP/1.1
txresp -hdr "Cache-Control: max-age=120" -hdr "Connection: close" -body "012345\n"
txresp -hdr "Cache-Control: max-age=120" -hdr "Connection: close" -nodate -body "012345\n"
} -start
varnish v1 -arg "-sTransient=default,1m" -vcl+backend {
......
......@@ -2,13 +2,13 @@ varnishtest "Backend close retry"
server s1 -repeat 1 {
rxreq
txresp -bodylen 5
txresp -nodate -bodylen 5
rxreq
accept
rxreq
txresp -bodylen 6
txresp -nodate -bodylen 6
} -start
......
......@@ -4,7 +4,7 @@ server s1 {
rxreq
expect req.url == "/"
expect req.http.test == "yes"
txresp -body "fdsa"
txresp -nodate -body "fdsa"
} -start
varnish v1 -vcl+backend {
......
......@@ -3,7 +3,7 @@ varnishtest "Test backend fetch byte counters"
server s1 {
rxreq
expect req.url == "/1"
txresp -bodylen 1000
txresp -nodate -bodylen 1000
rxreq
expect req.url == "/2"
......
......@@ -3,7 +3,7 @@ varnishtest "very very very long return header"
server s1 {
rxreq
expect req.url == "/"
txresp -hdr "Location: ${string,repeat,8136,1}" -body {foo}
txresp -hdr "Location: ${string,repeat,8136,1}" -nodate -body {foo}
} -start
varnish v1 -vcl+backend {
......
......@@ -769,7 +769,7 @@ cmd_http_gunzip(CMD_ARGS)
static char* const *
http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
char *body, unsigned nohost)
char *body, unsigned nohost, unsigned nodate)
{
long bodylen = 0;
char *b, *c;
......@@ -785,12 +785,16 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
nolen = 1;
} else if (!strcmp(*av, "-nohost")) {
nohost = 1;
} else if (!strcmp(*av, "-nodate")) {
nodate = 1;
} else if (!strcmp(*av, "-hdr")) {
if (!strncasecmp(av[1], "Content-Length:", 15) ||
!strncasecmp(av[1], "Transfer-Encoding:", 18))
nolen = 1;
if (!strncasecmp(av[1], "Host:", 5))
nohost = 1;
if (!strncasecmp(av[1], "Date:", 5))
nodate = 1;
VSB_printf(hp->vsb, "%s%s", av[1], nl);
av++;
} else if (!strcmp(*av, "-hdrlen")) {
......@@ -865,6 +869,11 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
macro_cat(vl, hp->vsb, "localhost", NULL);
VSB_cat(hp->vsb, nl);
}
if (!nodate) {
VSB_cat(hp->vsb, "Date: ");
macro_cat(vl, hp->vsb, "date", NULL);
VSB_cat(hp->vsb, nl);
}
if (body != NULL && !nolen)
VSB_printf(hp->vsb, "Content-Length: %ld%s", bodylen, nl);
VSB_cat(hp->vsb, nl);
......@@ -914,6 +923,9 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
* \-nolen
* Don't include a Content-Length header.
*
* \-nodate
* Don't include a Date header in the response.
*
* \-hdr STRING
* Add STRING as a header, it must follow this format:
* "name: value". It can be called multiple times.
......@@ -988,7 +1000,7 @@ cmd_http_txresp(CMD_ARGS)
/* send a "Content-Length: 0" header unless something else happens */
REPLACE(body, "");
av = http_tx_parse_args(av, vl, hp, body, 1);
av = http_tx_parse_args(av, vl, hp, body, 1, 0);
if (*av != NULL)
vtc_fatal(hp->vl, "Unknown http txresp spec: %s\n", *av);
......@@ -1220,7 +1232,7 @@ cmd_http_txreq(CMD_ARGS)
"HTTP2-Settings: %s%s", nl, nl, up, nl);
nohost = strcmp(proto, "HTTP/1.1") != 0;
av = http_tx_parse_args(av, vl, hp, NULL, nohost);
av = http_tx_parse_args(av, vl, hp, NULL, nohost, 1);
if (*av != NULL)
vtc_fatal(hp->vl, "Unknown http txreq spec: %s\n", *av);
http_write(hp, 4, "txreq");
......
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