Skip to content
This repository was archived by the owner on May 26, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/vtc_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,32 @@ cmd_http_rxchunk(CMD_ARGS)
* Transmit a request
*/

struct args {
char **argv;
int argc;
};

static void
args_init(struct args *args)
{
memset(args, 0, sizeof *args);
}

static void
args_add(struct args *args, char *arg)
{
AN(args);
args->argv = realloc(args->argv, (args->argc + 1) * sizeof *args->argv);
AN(args->argv);
args->argv[args->argc++] = arg;
}

static void
args_free(struct args *args)
{
free(args->argv);
}

static void
cmd_http_txreq(CMD_ARGS)
{
Expand All @@ -1180,6 +1206,7 @@ cmd_http_txreq(CMD_ARGS)
const char *url = "/";
const char *proto = "HTTP/1.1";
const char *up = NULL;
struct args args;
unsigned nohost;

(void)vl;
Expand All @@ -1189,6 +1216,7 @@ cmd_http_txreq(CMD_ARGS)
av++;

VSB_clear(hp->vsb);
args_init(&args);

hp->head_method = 0;
for (; *av != NULL; av++) {
Expand All @@ -1207,17 +1235,19 @@ cmd_http_txreq(CMD_ARGS)
up = av[1];
av++;
} else
break;
args_add(&args, *av);
}
VSB_printf(hp->vsb, "%s %s %s%s", req, url, proto, nl);

args_add(&args, NULL);

if (up)
VSB_printf(hp->vsb, "Connection: Upgrade, HTTP2-Settings%s"
"Upgrade: h2c%s"
"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(args.argv, vl, hp, NULL, nohost);
if (*av != NULL)
vtc_fatal(hp->vl, "Unknown http txreq spec: %s\n", *av);
http_write(hp, 4, "txreq");
Expand All @@ -1241,6 +1271,7 @@ cmd_http_txreq(CMD_ARGS)
"} -start\n"
);
}
args_free(&args);
}

/* SECTION: client-server.spec.recv
Expand Down
44 changes: 44 additions & 0 deletions tests/a00024.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
vtest "test -nouseragent and -noserver"

server s1 {
rxreq
# by default, User-Agent header is set to cNAME
expect req.http.User-Agent == "c101"
txresp
rxreq
# when specified with -hdr, it overrides the default
expect req.http.User-Agent == "not-c101"
txresp -hdr "Server: not-s1"
} -start

server s2 {
rxreq
expect req.http.User-Agent == "c202"
txresp
rxreq
# default User-Agent header is not included when -nouseragent is specified
expect req.http.foo == bar
expect req.http.User-Agent == <undef>
txresp -noserver
} -start

client c101 -connect ${s1_sock} {
txreq -url "/home"
rxresp
# by default, Server header is set to sNAME
expect resp.http.Server == "s1"
txreq -url "/home" -hdr "User-Agent: not-c101"
rxresp
# when specified with -hdr, it overrides the default
expect resp.http.Server == "not-s1"
} -run

client c202 -connect ${s2_sock} {
txreq
rxresp
expect resp.http.Server == "s2"
txreq -hdr "foo: bar" -nouseragent
rxresp
# default Server header is not included when -noserver is specified
expect resp.http.Server == <undef>
} -run