Commit 65242d1d authored by Walid Boudebouda's avatar Walid Boudebouda

vtc: add User-Agent: cNAME header by default

by default, add "User-Agent: cNAME" header to all client txreq requests
if not already present (via -hdr). This can be disabled with -nouseragent
parent 3368ee06
varnishtest "test -noserver" varnishtest "test -nouseragent and -noserver"
server s1 { server s1 {
rxreq rxreq
# by default, User-Agent header is set to cNAME
expect req.http.User-Agent == "c101"
txresp txresp
rxreq rxreq
# when specified with -hdr, it overrides the default
expect req.http.User-Agent == "not-c101"
txresp -hdr "Server: not-s1" txresp -hdr "Server: not-s1"
} -start } -start
server s2 { server s2 {
rxreq rxreq
expect req.http.User-Agent == "c202"
txresp txresp
rxreq rxreq
# default User-Agent header is not included when -nouseragent is specified
expect req.http.User-Agent == <undef>
txresp -noserver txresp -noserver
} -start } -start
...@@ -35,7 +42,7 @@ client c101 { ...@@ -35,7 +42,7 @@ client c101 {
rxresp rxresp
# by default, Server header is set to sNAME # by default, Server header is set to sNAME
expect resp.http.Server == "s1" expect resp.http.Server == "s1"
txreq -url "/home" txreq -url "/home" -hdr "User-Agent: not-c101"
rxresp rxresp
# when specified with -hdr, it overrides the default # when specified with -hdr, it overrides the default
expect resp.http.Server == "not-s1" expect resp.http.Server == "not-s1"
...@@ -45,7 +52,7 @@ client c202 { ...@@ -45,7 +52,7 @@ client c202 {
txreq txreq
rxresp rxresp
expect resp.http.Server == "s2" expect resp.http.Server == "s2"
txreq txreq -nouseragent
rxresp rxresp
# default Server header is not included when -noserver is specified # default Server header is not included when -noserver is specified
expect resp.http.Server == <undef> expect resp.http.Server == <undef>
......
...@@ -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 182 75 257$" expect * = ReqAcct "^45 0 45 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 187 75 262$" expect * = ReqAcct "^45 0 45 187 75 262$"
expect 0 = End expect 0 = End
} -start } -start
......
...@@ -26,8 +26,9 @@ varnish v1 -vcl+backend { ...@@ -26,8 +26,9 @@ varnish v1 -vcl+backend {
# POST /1 HTTP/1.1\r\n 18 bytes # POST /1 HTTP/1.1\r\n 18 bytes
# Host: foo\r\n 11 bytes # Host: foo\r\n 11 bytes
# Content-Length: 4\r\n 19 bytes # Content-Length: 4\r\n 19 bytes
# User-Agent: c1\r\n 16 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 50 bytes # Total: 66 bytes
# 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
...@@ -75,7 +76,7 @@ varnish v1 -vcl+backend { ...@@ -75,7 +76,7 @@ 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 99 1000 1099$" expect * = ReqAcct "^66 4 70 99 1000 1099$"
expect 0 = End expect 0 = End
expect * 1003 Begin "^req .* rxreq" expect * 1003 Begin "^req .* rxreq"
expect * = ReqAcct "^30 0 30 99 2000 2099$" expect * = ReqAcct "^30 0 30 99 2000 2099$"
...@@ -111,7 +112,7 @@ client c1 { ...@@ -111,7 +112,7 @@ client c1 {
logexpect l1 -wait logexpect l1 -wait
varnish v1 -expect s_req_hdrbytes == 117 varnish v1 -expect s_req_hdrbytes == 133
varnish v1 -expect s_req_bodybytes == 4 varnish v1 -expect s_req_bodybytes == 4
varnish v1 -expect s_resp_hdrbytes == 325 varnish v1 -expect s_resp_hdrbytes == 325
varnish v1 -expect s_resp_bodybytes == 5000 varnish v1 -expect s_resp_bodybytes == 5000
...@@ -31,8 +31,9 @@ varnish v1 -vcl+backend { ...@@ -31,8 +31,9 @@ varnish v1 -vcl+backend {
# Request (1001): # Request (1001):
# GET / HTTP/1.1\r\n 16 bytes # GET / HTTP/1.1\r\n 16 bytes
# Host: foo\r\n 11 bytes # Host: foo\r\n 11 bytes
# User-Agent: c1\r\n 16 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 29 bytes # Total: 45 bytes
# Reponse: # Reponse:
# HTTP/1.1 200 OK\r\n 17 bytes # HTTP/1.1 200 OK\r\n 17 bytes
...@@ -64,7 +65,7 @@ varnish v1 -vcl+backend { ...@@ -64,7 +65,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 105 15 120$" expect * = ReqAcct "^45 0 45 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$"
...@@ -86,7 +87,7 @@ client c1 { ...@@ -86,7 +87,7 @@ client c1 {
logexpect l1 -wait logexpect l1 -wait
varnish v1 -expect s_req_hdrbytes == 29 varnish v1 -expect s_req_hdrbytes == 45
varnish v1 -expect s_req_bodybytes == 0 varnish v1 -expect s_req_bodybytes == 0
varnish v1 -expect s_resp_hdrbytes == 105 varnish v1 -expect s_resp_hdrbytes == 105
varnish v1 -expect s_resp_bodybytes == 15 varnish v1 -expect s_resp_bodybytes == 15
...@@ -26,15 +26,18 @@ varnish v1 -vcl+backend { ...@@ -26,15 +26,18 @@ varnish v1 -vcl+backend {
# POST / HTTP/1.1\r\n 17 bytes # POST / HTTP/1.1\r\n 17 bytes
# Host: foo\r\n 11 bytes # Host: foo\r\n 11 bytes
# Content-Length: 4\r\n 19 bytes # Content-Length: 4\r\n 19 bytes
# User-Agent: c1\r\n 16 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 49 bytes # Total: 65 bytes
# bereq: # bereq:
# POST / HTTP/1.1\r\n 17 bytes # POST / HTTP/1.1\r\n 17 bytes
# Content-Length: 4\r\n 19 bytes # Content-Length: 4\r\n 19 bytes
# Host: foo\r\n 11 bytes
# User-Agent: c1\r\n 16 bytes
# test: yes\r\n 11 bytes # test: yes\r\n 11 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 49 bytes # Total: 76 bytes
# reqbody # reqbody
# asdf 4 bytes # asdf 4 bytes
...@@ -49,7 +52,7 @@ varnish v1 -vcl+backend { ...@@ -49,7 +52,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 * = PipeAcct "^49 60 4 54$" expect * = PipeAcct "^65 76 4 54$"
expect 0 = End expect 0 = End
} -start } -start
...@@ -62,6 +65,6 @@ client c1 { ...@@ -62,6 +65,6 @@ client c1 {
logexpect l1 -wait logexpect l1 -wait
varnish v1 -expect s_pipe_hdrbytes == 49 varnish v1 -expect s_pipe_hdrbytes == 65
varnish v1 -expect s_pipe_in == 4 varnish v1 -expect s_pipe_in == 4
varnish v1 -expect s_pipe_out == 54 varnish v1 -expect s_pipe_out == 54
...@@ -28,9 +28,10 @@ varnish v1 -vcl+backend { ...@@ -28,9 +28,10 @@ varnish v1 -vcl+backend {
# Request (1002): # Request (1002):
# POST /1 HTTP/1.1\r\n 18 bytes # POST /1 HTTP/1.1\r\n 18 bytes
# Content-Length: 4\r\n 19 bytes # Content-Length: 4\r\n 19 bytes
# User-Agent: c1\r\n 16 bytes
# Host: foo.bar\r\n 15 bytes # Host: foo.bar\r\n 15 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 54 bytes # Total: 70 bytes
# 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
...@@ -41,9 +42,10 @@ varnish v1 -vcl+backend { ...@@ -41,9 +42,10 @@ varnish v1 -vcl+backend {
# Request (1004): # Request (1004):
# POST /2 HTTP/1.1\r\n 18 bytes # POST /2 HTTP/1.1\r\n 18 bytes
# Content-Length: 4\r\n 19 bytes # Content-Length: 4\r\n 19 bytes
# User-Agent: c1\r\n 16 bytes
# Host: foo.bar\r\n 15 bytes # Host: foo.bar\r\n 15 bytes
# \r\n 2 bytes # \r\n 2 bytes
# Total: 54 bytes # Total: 70 bytes
# Reponse: # Reponse:
# HTTP/1.1\r\n 10 bytes # HTTP/1.1\r\n 10 bytes
# \r\n 2 bytes # \r\n 2 bytes
...@@ -55,10 +57,10 @@ logexpect l1 -v v1 -g session { ...@@ -55,10 +57,10 @@ 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 53 1000 1053$" expect * = BereqAcct "^70 4 74 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 "^70 4 74 12 0 12$"
expect * = End expect * = End
} -start } -start
......
...@@ -25,7 +25,7 @@ varnish v1 -arg "-sdefault,1M" -arg "-p nuke_limit=0 -p gzip_level=0" \ ...@@ -25,7 +25,7 @@ varnish v1 -arg "-sdefault,1M" -arg "-p nuke_limit=0 -p gzip_level=0" \
} -start } -start
logexpect l1 -v v1 -g vxid -q "vxid == 1004" { logexpect l1 -v v1 -g vxid -q "vxid == 1004" {
expect 25 1004 VCL_call {^BACKEND_RESPONSE} expect 26 1004 VCL_call {^BACKEND_RESPONSE}
expect 0 = BerespHeader {^free:} expect 0 = BerespHeader {^free:}
expect 0 = VCL_return {^deliver} expect 0 = VCL_return {^deliver}
expect 0 = Timestamp {^Process} expect 0 = Timestamp {^Process}
......
...@@ -34,9 +34,9 @@ process p1 -winsz 25 200 {varnishncsa -n ${v1_name}} -start ...@@ -34,9 +34,9 @@ process p1 -winsz 25 200 {varnishncsa -n ${v1_name}} -start
delay 1 delay 1
client c1 { client c1 {
txreq -url /1?foo=bar -hdr "authorization: basic dXNlcjpwYXNz" txreq -nouseragent -url /1?foo=bar -hdr "authorization: basic dXNlcjpwYXNz"
rxresp rxresp
txreq -url /1?foo=bar -hdr "baz: qux" txreq -nouseragent -url /1?foo=bar -hdr "baz: qux"
rxresp rxresp
} -run } -run
...@@ -46,7 +46,7 @@ shell "mv ${tmpdir}/ncsa.log ${tmpdir}/ncsa.old.log" ...@@ -46,7 +46,7 @@ shell "mv ${tmpdir}/ncsa.log ${tmpdir}/ncsa.old.log"
shell "kill -HUP `cat ${tmpdir}/ncsa.pid`" shell "kill -HUP `cat ${tmpdir}/ncsa.pid`"
client c2 { client c2 {
txreq -url /2 txreq -nouseragent -url /2
rxresp rxresp
} -run } -run
......
...@@ -188,6 +188,7 @@ logexpect l1012 -v v1 -g vxid -q "vxid == 1012" { ...@@ -188,6 +188,7 @@ logexpect l1012 -v v1 -g vxid -q "vxid == 1012" {
expect 0 = BereqProtocol {^HTTP/1.1} expect 0 = BereqProtocol {^HTTP/1.1}
expect 0 = BereqHeader {^foo: pipe} expect 0 = BereqHeader {^foo: pipe}
expect 0 = BereqHeader {^Host: } expect 0 = BereqHeader {^Host: }
expect 0 = BereqHeader {^User-Agent: c1}
expect 0 = BereqHeader {^X-Forwarded-For: } expect 0 = BereqHeader {^X-Forwarded-For: }
expect 0 = BereqHeader {^Via: } expect 0 = BereqHeader {^Via: }
expect 0 = BereqHeader {^X-Varnish: 1011} expect 0 = BereqHeader {^X-Varnish: 1011}
...@@ -207,6 +208,7 @@ logexpect l1011 -v v1 -g vxid -q "vxid == 1011" { ...@@ -207,6 +208,7 @@ logexpect l1011 -v v1 -g vxid -q "vxid == 1011" {
expect 0 = ReqProtocol {^HTTP/1.1} expect 0 = ReqProtocol {^HTTP/1.1}
expect 0 = ReqHeader {^foo: pipe} expect 0 = ReqHeader {^foo: pipe}
expect 0 = ReqHeader {^Host: } expect 0 = ReqHeader {^Host: }
expect 0 = reqHeader {^User-Agent: c1}
expect 0 = ReqHeader {^X-Forwarded-For: } expect 0 = ReqHeader {^X-Forwarded-For: }
expect 0 = ReqHeader {^Via: } expect 0 = ReqHeader {^Via: }
expect 0 = VCL_call {^RECV} expect 0 = VCL_call {^RECV}
......
...@@ -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, unsigned noserver) char *body, unsigned nohost, unsigned nodate, unsigned noserver, unsigned nouseragent)
{ {
long bodylen = 0; long bodylen = 0;
char *b, *c; char *b, *c;
...@@ -797,6 +797,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -797,6 +797,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
nodate = 1; nodate = 1;
if (!strncasecmp(av[1], "Server:", 7)) if (!strncasecmp(av[1], "Server:", 7))
noserver = 1; noserver = 1;
if (!strncasecmp(av[1], "User-Agent:", 11))
nouseragent = 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")) {
...@@ -863,6 +865,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -863,6 +865,8 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
} }
if (!noserver) if (!noserver)
VSB_printf(hp->vsb, "Server: %s%s", hp->sess->name, nl); VSB_printf(hp->vsb, "Server: %s%s", hp->sess->name, nl);
if (!nouseragent)
VSB_printf(hp->vsb, "User-Agent: %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);
...@@ -906,6 +910,9 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, ...@@ -906,6 +910,9 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
* \-noserver (txresp only) * \-noserver (txresp only)
* Don't include a Server header with the id of the server. * Don't include a Server header with the id of the server.
* *
* \-nouseragent (txreq only)
* Don't include a User-Agent header with the id of the client.
*
* 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.
* *
...@@ -1000,7 +1007,7 @@ cmd_http_txresp(CMD_ARGS) ...@@ -1000,7 +1007,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, noserver); av = http_tx_parse_args(av, vl, hp, body, 1, 0, noserver, 1);
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);
...@@ -1196,6 +1203,7 @@ cmd_http_txreq(CMD_ARGS) ...@@ -1196,6 +1203,7 @@ cmd_http_txreq(CMD_ARGS)
const char *proto = "HTTP/1.1"; const char *proto = "HTTP/1.1";
const char *up = NULL; const char *up = NULL;
unsigned nohost; unsigned nohost;
unsigned nouseragent = 0;
(void)vl; (void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
...@@ -1221,6 +1229,8 @@ cmd_http_txreq(CMD_ARGS) ...@@ -1221,6 +1229,8 @@ cmd_http_txreq(CMD_ARGS)
} else if (!hp->sfd && !strcmp(*av, "-up")) { } else if (!hp->sfd && !strcmp(*av, "-up")) {
up = av[1]; up = av[1];
av++; av++;
} else if (!strcmp(*av, "-nouseragent")) {
nouseragent = 1;
} else } else
break; break;
} }
...@@ -1232,7 +1242,7 @@ cmd_http_txreq(CMD_ARGS) ...@@ -1232,7 +1242,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, 1); av = http_tx_parse_args(av, vl, hp, NULL, nohost, 1, 1, nouseragent);
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