Skip to content
Open
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 @@ -1210,6 +1210,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 @@ -1218,6 +1244,7 @@ cmd_http_txreq(CMD_ARGS)
const char *url = "/";
const char *proto = "HTTP/1.1";
const char *up = NULL;
struct args args;
unsigned nohost;
unsigned nouseragent = 0;

Expand All @@ -1228,6 +1255,7 @@ cmd_http_txreq(CMD_ARGS)
av++;

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

hp->head_method = 0;
for (; *av != NULL; av++) {
Expand All @@ -1248,17 +1276,19 @@ cmd_http_txreq(CMD_ARGS)
} else if (!strcmp(*av, "-nouseragent")) {
nouseragent = 1;
} 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, 1, 1, nouseragent);
av = http_tx_parse_args(args.argv, vl, hp, NULL, nohost, 1, 1, nouseragent);
if (*av != NULL)
vtc_fatal(hp->vl, "Unknown http txreq spec: %s\n", *av);
http_write(hp, 4, "txreq");
Expand All @@ -1282,6 +1312,7 @@ cmd_http_txreq(CMD_ARGS)
"} -start\n"
);
}
args_free(&args);
}

/* SECTION: client-server.spec.recv
Expand Down
3 changes: 2 additions & 1 deletion tests/a00024.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ server s2 {
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
Expand All @@ -36,7 +37,7 @@ client c202 -connect ${s2_sock} {
txreq
rxresp
expect resp.http.Server == "s2"
txreq -nouseragent
txreq -hdr "foo: bar" -nouseragent
rxresp
# default Server header is not included when -noserver is specified
expect resp.http.Server == <undef>
Expand Down