Commit 3368ee06 authored by Walid Boudebouda's avatar Walid Boudebouda

vtc: add Server: sNAME header by default

by default, add a "Server: sNAME" header to all server txresp responses
if not already present (via -hdr). adding -noserver to txresp will
disable it. Note that for -dispatch servers, the id of the spawned server
(sN) will be used instead of s0.
parent 3731e9f9
varnishtest "test -noserver"
server s1 {
rxreq
txresp
rxreq
txresp -hdr "Server: not-s1"
} -start
server s2 {
rxreq
txresp
rxreq
txresp -noserver
} -start
varnish v1 -vcl+backend {
sub vcl_recv {
if (req.url == "/home") {
set req.backend_hint = s1;
} else {
set req.backend_hint = s2;
}
}
sub vcl_backend_response {
set Beresp.uncacheable = true;
}
} -start
client c101 {
txreq -url "/home"
rxresp
# by default, Server header is set to sNAME
expect resp.http.Server == "s1"
txreq -url "/home"
rxresp
# when specified with -hdr, it overrides the default
expect resp.http.Server == "not-s1"
} -run
client c202 {
txreq
rxresp
expect resp.http.Server == "s2"
txreq
rxresp
# default Server header is not included when -noserver is specified
expect resp.http.Server == <undef>
} -run
...@@ -52,8 +52,7 @@ varnish v1 -expect client_req == 1 ...@@ -52,8 +52,7 @@ varnish v1 -expect client_req == 1
varnish v1 -expect cache_miss == 1 varnish v1 -expect cache_miss == 1
varnish v1 -expect s_sess == 1 varnish v1 -expect s_sess == 1
varnish v1 -expect s_resp_bodybytes == 7 varnish v1 -expect s_resp_bodybytes == 7
varnish v1 -expect s_resp_hdrbytes == 146 varnish v1 -expect s_resp_hdrbytes == 158
client c1 { client c1 {
txreq -url "/2" txreq -url "/2"
rxresp rxresp
...@@ -67,4 +66,4 @@ varnish v1 -expect client_req == 2 ...@@ -67,4 +66,4 @@ varnish v1 -expect client_req == 2
varnish v1 -expect cache_miss == 2 varnish v1 -expect cache_miss == 2
varnish v1 -expect s_sess == 2 varnish v1 -expect s_sess == 2
varnish v1 -expect s_resp_bodybytes == 14 varnish v1 -expect s_resp_bodybytes == 14
varnish v1 -expect s_resp_hdrbytes == 292 varnish v1 -expect s_resp_hdrbytes == 316
...@@ -35,7 +35,7 @@ varnish v1 -expect client_req == 1 ...@@ -35,7 +35,7 @@ varnish v1 -expect client_req == 1
varnish v1 -expect cache_miss == 1 varnish v1 -expect cache_miss == 1
varnish v1 -expect s_sess == 1 varnish v1 -expect s_sess == 1
varnish v1 -expect s_resp_bodybytes == 7 varnish v1 -expect s_resp_bodybytes == 7
varnish v1 -expect s_resp_hdrbytes == 146 varnish v1 -expect s_resp_hdrbytes == 158
# varnishtest "vtc v_* macros when the listen address is UDS" (a00019) # varnishtest "vtc v_* macros when the listen address is UDS" (a00019)
......
...@@ -2,13 +2,13 @@ varnishtest "Backend close retry" ...@@ -2,13 +2,13 @@ varnishtest "Backend close retry"
server s1 -repeat 1 { server s1 -repeat 1 {
rxreq rxreq
txresp -nodate -bodylen 5 txresp -noserver -nodate -bodylen 5
rxreq rxreq
accept accept
rxreq rxreq
txresp -nodate -bodylen 6 txresp -noserver -nodate -bodylen 6
} -start } -start
......
...@@ -50,7 +50,7 @@ varnish v1 -vcl+backend { ...@@ -50,7 +50,7 @@ varnish v1 -vcl+backend {
logexpect l1 -v v1 -g request { logexpect l1 -v v1 -g request {
expect 0 1001 Begin "^req .* rxreq" expect 0 1001 Begin "^req .* rxreq"
expect * = ReqAcct "^29 0 29 170 75 245$" expect * = ReqAcct "^29 0 29 182 75 257$"
expect 0 = End expect 0 = End
} -start } -start
...@@ -73,7 +73,7 @@ logexpect l4 -v v1 -g request { ...@@ -73,7 +73,7 @@ logexpect l4 -v v1 -g request {
logexpect l5 -v v1 -g request { logexpect l5 -v v1 -g request {
expect * 1006 Begin "^req .* rxreq" expect * 1006 Begin "^req .* rxreq"
# Header bytes is 5 larger than in l1 due to two item X-Varnish hdr # Header bytes is 5 larger than in l1 due to two item X-Varnish hdr
expect * = ReqAcct "^29 0 29 175 75 250$" expect * = ReqAcct "^29 0 29 187 75 262$"
expect 0 = End expect 0 = End
} -start } -start
......
...@@ -33,8 +33,9 @@ varnish v1 -vcl+backend { ...@@ -33,8 +33,9 @@ varnish v1 -vcl+backend {
# Content-Length: 1000\r\n 22 bytes # Content-Length: 1000\r\n 22 bytes
# Connection: keep-alive\r\n 24 bytes # Connection: keep-alive\r\n 24 bytes
# Accept-Ranges: bytes\r\n 22 bytes # Accept-Ranges: bytes\r\n 22 bytes
# Server: s1\r\n 12 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 87 bytes # Total: 99 bytes
# Request (1003): # Request (1003):
# GET /2 HTTP/1.1\r\n 17 bytes # GET /2 HTTP/1.1\r\n 17 bytes
...@@ -46,8 +47,9 @@ varnish v1 -vcl+backend { ...@@ -46,8 +47,9 @@ varnish v1 -vcl+backend {
# Content-Length: 2000\r\n 22 bytes # Content-Length: 2000\r\n 22 bytes
# Connection: keep-alive\r\n 24 bytes # Connection: keep-alive\r\n 24 bytes
# Accept-Ranges: bytes\r\n 22 bytes # Accept-Ranges: bytes\r\n 22 bytes
# Server: s1\r\n 12 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 87 bytes # Total: 99 bytes
# Request (1005): # Request (1005):
# GET /2 HTTP/1.1\r\n 17 bytes # GET /2 HTTP/1.1\r\n 17 bytes
...@@ -59,8 +61,9 @@ varnish v1 -vcl+backend { ...@@ -59,8 +61,9 @@ varnish v1 -vcl+backend {
# Content-Length: 2000\r\n 22 bytes # Content-Length: 2000\r\n 22 bytes
# Connection: keep-alive\r\n 24 bytes # Connection: keep-alive\r\n 24 bytes
# Accept-Ranges: bytes\r\n 22 bytes # Accept-Ranges: bytes\r\n 22 bytes
# Server: s1\r\n 12 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 87 bytes # Total: 99 bytes
# Request (1006): # Request (1006):
# GET\r\n 5 bytes # GET\r\n 5 bytes
...@@ -72,13 +75,13 @@ varnish v1 -vcl+backend { ...@@ -72,13 +75,13 @@ varnish v1 -vcl+backend {
# Total: 28 bytes # Total: 28 bytes
logexpect l1 -v v1 -g session { logexpect l1 -v v1 -g session {
expect * 1001 Begin "^req .* rxreq" expect * 1001 Begin "^req .* rxreq"
expect * = ReqAcct "^50 4 54 87 1000 1087$" expect * = ReqAcct "^50 4 54 99 1000 1099$"
expect 0 = End expect 0 = End
expect * 1003 Begin "^req .* rxreq" expect * 1003 Begin "^req .* rxreq"
expect * = ReqAcct "^30 0 30 87 2000 2087$" expect * = ReqAcct "^30 0 30 99 2000 2099$"
expect 0 = End expect 0 = End
expect * 1005 Begin "^req .* rxreq" expect * 1005 Begin "^req .* rxreq"
expect * = ReqAcct "^30 0 30 87 2000 2087$" expect * = ReqAcct "^30 0 30 99 2000 2099$"
expect 0 = End expect 0 = End
expect * 1006 Begin "^req .* rxreq" expect * 1006 Begin "^req .* rxreq"
expect * = ReqAcct "^7 0 7 28 0 28$" expect * = ReqAcct "^7 0 7 28 0 28$"
...@@ -110,5 +113,5 @@ logexpect l1 -wait ...@@ -110,5 +113,5 @@ logexpect l1 -wait
varnish v1 -expect s_req_hdrbytes == 117 varnish v1 -expect s_req_hdrbytes == 117
varnish v1 -expect s_req_bodybytes == 4 varnish v1 -expect s_req_bodybytes == 4
varnish v1 -expect s_resp_hdrbytes == 289 varnish v1 -expect s_resp_hdrbytes == 325
varnish v1 -expect s_resp_bodybytes == 5000 varnish v1 -expect s_resp_bodybytes == 5000
...@@ -39,8 +39,9 @@ varnish v1 -vcl+backend { ...@@ -39,8 +39,9 @@ varnish v1 -vcl+backend {
# Accept-Ranges: bytes\r\n 22 bytes # Accept-Ranges: bytes\r\n 22 bytes
# Transfer-Encoding: chunked\r\n 28 bytes # Transfer-Encoding: chunked\r\n 28 bytes
# Connection: keep-alive\r\n 24 bytes # Connection: keep-alive\r\n 24 bytes
# Server: s1\r\n 12 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 93 bytes # Total: 105 bytes
# Response body: # Response body:
# Chunk len - bytes # Chunk len - bytes
...@@ -63,7 +64,7 @@ varnish v1 -vcl+backend { ...@@ -63,7 +64,7 @@ varnish v1 -vcl+backend {
logexpect l1 -v v1 -g request { logexpect l1 -v v1 -g request {
expect 0 1001 Begin "^req .* rxreq" expect 0 1001 Begin "^req .* rxreq"
expect * = ReqAcct "^29 0 29 93 15 108$" expect * = ReqAcct "^29 0 29 105 15 120$"
expect 0 = End expect 0 = End
expect * 1003 Begin "^req .* esi" expect * 1003 Begin "^req .* esi"
expect * = ReqAcct "^0 0 0 0 12 12$" expect * = ReqAcct "^0 0 0 0 12 12$"
...@@ -87,5 +88,5 @@ logexpect l1 -wait ...@@ -87,5 +88,5 @@ logexpect l1 -wait
varnish v1 -expect s_req_hdrbytes == 29 varnish v1 -expect s_req_hdrbytes == 29
varnish v1 -expect s_req_bodybytes == 0 varnish v1 -expect s_req_bodybytes == 0
varnish v1 -expect s_resp_hdrbytes == 93 varnish v1 -expect s_resp_hdrbytes == 105
varnish v1 -expect s_resp_bodybytes == 15 varnish v1 -expect s_resp_bodybytes == 15
...@@ -42,13 +42,14 @@ varnish v1 -vcl+backend { ...@@ -42,13 +42,14 @@ varnish v1 -vcl+backend {
# resp: # resp:
# HTTP/1.1 200 OK\r\n 17 bytes # HTTP/1.1 200 OK\r\n 17 bytes
# Content-Length: 4\r\n 19 bytes # Content-Length: 4\r\n 19 bytes
# Server: s1\r\n 12 bytes
# \r\n 2 bytes # \r\n 2 bytes
# fdsa 4 bytes # fdsa 4 bytes
# Total: 42 bytes # Total: 54 bytes
logexpect l1 -v v1 -g request { logexpect l1 -v v1 -g request {
expect 0 1001 Begin "^req .* rxreq" expect 0 1001 Begin "^req .* rxreq"
expect * = PipeAcct "^49 60 4 42$" expect * = PipeAcct "^49 60 4 54$"
expect 0 = End expect 0 = End
} -start } -start
...@@ -63,4 +64,4 @@ logexpect l1 -wait ...@@ -63,4 +64,4 @@ logexpect l1 -wait
varnish v1 -expect s_pipe_hdrbytes == 49 varnish v1 -expect s_pipe_hdrbytes == 49
varnish v1 -expect s_pipe_in == 4 varnish v1 -expect s_pipe_in == 4
varnish v1 -expect s_pipe_out == 42 varnish v1 -expect s_pipe_out == 54
...@@ -34,8 +34,9 @@ varnish v1 -vcl+backend { ...@@ -34,8 +34,9 @@ varnish v1 -vcl+backend {
# Response: # Response:
# HTTP/1.1 200 OK\r\n 17 bytes # HTTP/1.1 200 OK\r\n 17 bytes
# Content-Length: 1000\r\n 22 bytes # Content-Length: 1000\r\n 22 bytes
# Server: s1\r\n 12 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 41 bytes # Total: 53 bytes
# Request (1004): # Request (1004):
# POST /2 HTTP/1.1\r\n 18 bytes # POST /2 HTTP/1.1\r\n 18 bytes
...@@ -54,7 +55,7 @@ logexpect l1 -v v1 -g session { ...@@ -54,7 +55,7 @@ logexpect l1 -v v1 -g session {
expect 0 1003 Begin "^req .* rxreq" expect 0 1003 Begin "^req .* rxreq"
expect * = End expect * = End
expect 0 1002 Begin "^bereq " expect 0 1002 Begin "^bereq "
expect * = BereqAcct "^54 4 58 41 1000 1041$" expect * = BereqAcct "^54 4 58 53 1000 1053$"
expect 0 = End expect 0 = End
expect 0 1004 Begin "^bereq" expect 0 1004 Begin "^bereq"
expect * = BereqAcct "^54 4 58 12 0 12$" expect * = BereqAcct "^54 4 58 12 0 12$"
......
...@@ -4,18 +4,18 @@ server s1 { ...@@ -4,18 +4,18 @@ server s1 {
# This response should almost completely fill the storage # This response should almost completely fill the storage
rxreq rxreq
expect req.url == /url1 expect req.url == /url1
txresp -bodylen 1048400 txresp -noserver -bodylen 1048400
# The next one should not fit in the storage, ending up in transient # The next one should not fit in the storage, ending up in transient
# with zero ttl (=shortlived) # with zero ttl (=shortlived)
rxreq rxreq
expect req.url == /url2 expect req.url == /url2
txresp -bodylen 1024 txresp -noserver -bodylen 1024
# And therefore this one should be fetched next # And therefore this one should be fetched next
rxreq rxreq
expect req.url == /url2 expect req.url == /url2
txresp -bodylen 1025 txresp -noserver -bodylen 1025
} -start } -start
varnish v1 -arg "-p nuke_limit=0 -p shortlived=0" \ varnish v1 -arg "-p nuke_limit=0 -p shortlived=0" \
......
...@@ -3,7 +3,7 @@ varnishtest "#2831: Out of storage in cache_req_body" ...@@ -3,7 +3,7 @@ varnishtest "#2831: Out of storage in cache_req_body"
server s1 { server s1 {
rxreq rxreq
expect req.url == "/obj1" expect req.url == "/obj1"
txresp -bodylen 1048400 txresp -noserver -bodylen 1048400
} -start } -start
varnish v1 \ varnish v1 \
......
...@@ -7,10 +7,10 @@ server s1 { ...@@ -7,10 +7,10 @@ server s1 {
rxreq rxreq
expect req.http.content-length == 7 expect req.http.content-length == 7
expect req.http.transfer-encoding == <undef> expect req.http.transfer-encoding == <undef>
txresp -hdr "Accept-ranges: bytes" -hdr "Content-Type: text/plain" -body response txresp -noserver -hdr "Accept-ranges: bytes" -hdr "Content-Type: text/plain" -body response
rxreq rxreq
txresp -hdr "Accept-ranges: bytes" txresp -noserver -hdr "Accept-ranges: bytes"
} -start } -start
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
......
...@@ -2,7 +2,7 @@ varnishtest "h2 ReqAcct" ...@@ -2,7 +2,7 @@ varnishtest "h2 ReqAcct"
server s1 { server s1 {
rxreq rxreq
txresp -bodylen 12345 txresp -noserver -bodylen 12345
} -start } -start
varnish v1 -cliok "param.set feature +http2" varnish v1 -cliok "param.set feature +http2"
......
...@@ -22,7 +22,7 @@ client c1 { ...@@ -22,7 +22,7 @@ client c1 {
varnish v1 -vsl_catchup varnish v1 -vsl_catchup
process p1 -expect-text 1 1 {list length 6} process p1 -expect-text 1 1 {list length 7}
process p1 -writehex 0c process p1 -writehex 0c
......
...@@ -3,16 +3,16 @@ varnishtest "vbf_stp_condfetch could not get storage #3273" ...@@ -3,16 +3,16 @@ varnishtest "vbf_stp_condfetch could not get storage #3273"
server s1 { server s1 {
rxreq rxreq
expect req.url == "/transient" expect req.url == "/transient"
txresp -bodylen 1048400 txresp -noserver -bodylen 1048400
rxreq rxreq
expect req.url == "/malloc" expect req.url == "/malloc"
txresp -hdr "Cache-Control: max-age=2" -hdr "Last-Modified: Fri, 03 Apr 2020 13:00:01 GMT" -bodylen 1048292 txresp -noserver -hdr "Cache-Control: max-age=2" -hdr "Last-Modified: Fri, 03 Apr 2020 13:00:01 GMT" -bodylen 1048292
rxreq rxreq
expect req.http.If-Modified-Since == "Fri, 03 Apr 2020 13:00:01 GMT" expect req.http.If-Modified-Since == "Fri, 03 Apr 2020 13:00:01 GMT"
expect req.url == "/malloc" expect req.url == "/malloc"
txresp -status 304 txresp -noserver -status 304
} -start } -start
varnish v1 \ varnish v1 \
......
...@@ -769,7 +769,7 @@ cmd_http_gunzip(CMD_ARGS) ...@@ -769,7 +769,7 @@ cmd_http_gunzip(CMD_ARGS)
static char* const * static char* const *
http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
char *body, unsigned nohost, unsigned nodate) char *body, unsigned nohost, unsigned nodate, unsigned noserver)
{ {
long bodylen = 0; long bodylen = 0;
char *b, *c; char *b, *c;
...@@ -795,6 +795,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -795,6 +795,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
nohost = 1; nohost = 1;
if (!strncasecmp(av[1], "Date:", 5)) if (!strncasecmp(av[1], "Date:", 5))
nodate = 1; nodate = 1;
if (!strncasecmp(av[1], "Server:", 7))
noserver = 1;
VSB_printf(hp->vsb, "%s%s", av[1], nl); VSB_printf(hp->vsb, "%s%s", av[1], nl);
av++; av++;
} else if (!strcmp(*av, "-hdrlen")) { } else if (!strcmp(*av, "-hdrlen")) {
...@@ -859,6 +861,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -859,6 +861,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
macro_cat(vl, hp->vsb, "date", NULL); macro_cat(vl, hp->vsb, "date", NULL);
VSB_cat(hp->vsb, nl); VSB_cat(hp->vsb, nl);
} }
if (!noserver)
VSB_printf(hp->vsb, "Server: %s%s", hp->sess->name, nl);
if (body != NULL && !nolen) if (body != NULL && !nolen)
VSB_printf(hp->vsb, "Content-Length: %ld%s", bodylen, nl); VSB_printf(hp->vsb, "Content-Length: %ld%s", bodylen, nl);
VSB_cat(hp->vsb, nl); VSB_cat(hp->vsb, nl);
...@@ -899,6 +903,9 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -899,6 +903,9 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
* \-reason STRING (txresp only) * \-reason STRING (txresp only)
* What message to put in the status line (default: "OK"). * What message to put in the status line (default: "OK").
* *
* \-noserver (txresp only)
* Don't include a Server header with the id of the server.
*
* These three switches can appear in any order but must come before the * These three switches can appear in any order but must come before the
* following ones. * following ones.
* *
...@@ -960,6 +967,7 @@ cmd_http_txresp(CMD_ARGS) ...@@ -960,6 +967,7 @@ cmd_http_txresp(CMD_ARGS)
const char *status = "200"; const char *status = "200";
const char *reason = "OK"; const char *reason = "OK";
char* body = NULL; char* body = NULL;
unsigned noserver = 0;
(void)vl; (void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
...@@ -980,6 +988,9 @@ cmd_http_txresp(CMD_ARGS) ...@@ -980,6 +988,9 @@ cmd_http_txresp(CMD_ARGS)
reason = av[1]; reason = av[1];
av++; av++;
continue; continue;
} else if (!strcmp(*av, "-noserver")) {
noserver = 1;
continue;
} else } else
break; break;
} }
...@@ -989,7 +1000,7 @@ cmd_http_txresp(CMD_ARGS) ...@@ -989,7 +1000,7 @@ cmd_http_txresp(CMD_ARGS)
/* send a "Content-Length: 0" header unless something else happens */ /* send a "Content-Length: 0" header unless something else happens */
REPLACE(body, ""); REPLACE(body, "");
av = http_tx_parse_args(av, vl, hp, body, 1, 0); av = http_tx_parse_args(av, vl, hp, body, 1, 0, noserver);
if (*av != NULL) if (*av != NULL)
vtc_fatal(hp->vl, "Unknown http txresp spec: %s\n", *av); vtc_fatal(hp->vl, "Unknown http txresp spec: %s\n", *av);
...@@ -1221,7 +1232,7 @@ cmd_http_txreq(CMD_ARGS) ...@@ -1221,7 +1232,7 @@ cmd_http_txreq(CMD_ARGS)
"HTTP2-Settings: %s%s", nl, nl, up, nl); "HTTP2-Settings: %s%s", nl, nl, up, nl);
nohost = strcmp(proto, "HTTP/1.1") != 0; nohost = strcmp(proto, "HTTP/1.1") != 0;
av = http_tx_parse_args(av, vl, hp, NULL, nohost, 1); av = http_tx_parse_args(av, vl, hp, NULL, nohost, 1, 1);
if (*av != NULL) if (*av != NULL)
vtc_fatal(hp->vl, "Unknown http txreq spec: %s\n", *av); vtc_fatal(hp->vl, "Unknown http txreq spec: %s\n", *av);
http_write(hp, 4, "txreq"); 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