[master] ec0c5f4a5 varnishtest: txresp Date header by default

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Nov 28 15:33:06 UTC 2022


commit ec0c5f4a539c51de35e3c1b2897328244e9d0a63
Author: AlveElde <alve_elde at hotmail.com>
Date:   Thu Sep 15 12:57:19 2022 +0200

    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.

diff --git a/bin/varnishtest/tests/b00002.vtc b/bin/varnishtest/tests/b00002.vtc
index c3feb0722..63fde07a2 100644
--- a/bin/varnishtest/tests/b00002.vtc
+++ b/bin/varnishtest/tests/b00002.vtc
@@ -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 {
diff --git a/bin/varnishtest/tests/c00036.vtc b/bin/varnishtest/tests/c00036.vtc
index 97b51d5cc..adec31ab0 100644
--- a/bin/varnishtest/tests/c00036.vtc
+++ b/bin/varnishtest/tests/c00036.vtc
@@ -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
 
diff --git a/bin/varnishtest/tests/l00004.vtc b/bin/varnishtest/tests/l00004.vtc
index 5978af8b2..0bff118bb 100644
--- a/bin/varnishtest/tests/l00004.vtc
+++ b/bin/varnishtest/tests/l00004.vtc
@@ -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 {
diff --git a/bin/varnishtest/tests/l00005.vtc b/bin/varnishtest/tests/l00005.vtc
index 51667672a..12da731d0 100644
--- a/bin/varnishtest/tests/l00005.vtc
+++ b/bin/varnishtest/tests/l00005.vtc
@@ -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"
diff --git a/bin/varnishtest/tests/r00498.vtc b/bin/varnishtest/tests/r00498.vtc
index c11df3f77..2b08dc202 100644
--- a/bin/varnishtest/tests/r00498.vtc
+++ b/bin/varnishtest/tests/r00498.vtc
@@ -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 {
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index aada58c03..5f94452a8 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -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");


More information about the varnish-commit mailing list