[master] 3c2e42b71 Add -bodyfrom to read the body from a file
Federico G. Schwindt
fgsch at lodoss.net
Sat Apr 27 21:57:12 UTC 2019
commit 3c2e42b71c8f488adbc1b0045cce06de558f8863
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date: Sat Apr 27 18:52:18 2019 +0100
Add -bodyfrom to read the body from a file
Name subject to bikeshedding.
diff --git a/bin/varnishtest/tests/a00020.vtc b/bin/varnishtest/tests/a00020.vtc
new file mode 100644
index 000000000..6b50c11df
--- /dev/null
+++ b/bin/varnishtest/tests/a00020.vtc
@@ -0,0 +1,14 @@
+varnishtest "Test -bodyfrom"
+
+server s1 {
+ rxreq
+ expect req.bodylen == 241
+ txresp -bodyfrom ${testdir}/a00020.vtc
+} -start
+
+client c1 -connect ${s1_sock} {
+ txreq -bodyfrom ${testdir}/a00020.vtc
+ rxresp
+ expect resp.bodylen == 241
+} -run
+
diff --git a/bin/varnishtest/tests/a02025.vtc b/bin/varnishtest/tests/a02025.vtc
new file mode 100644
index 000000000..b3088d4d9
--- /dev/null
+++ b/bin/varnishtest/tests/a02025.vtc
@@ -0,0 +1,17 @@
+varnishtest "Test -bodyfrom"
+
+server s1 {
+ stream 1 {
+ rxreq
+ expect req.bodylen == 286
+ txresp -bodyfrom ${testdir}/a02025.vtc
+ } -run
+} -start
+
+client c1 -connect ${s1_sock} {
+ stream 1 {
+ txreq -bodyfrom ${testdir}/a02025.vtc
+ rxresp
+ expect resp.bodylen == 286
+ } -run
+} -run
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 041690caa..5d75e6ef4 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -868,6 +868,7 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
char *b, *c;
char *nullbody;
char *m;
+ ssize_t len;
int nolen = 0;
int l;
@@ -912,6 +913,14 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
bodylen--;
}
}
+ } else if (!strcmp(*av, "-bodyfrom")) {
+ assert(body == nullbody);
+ free(body);
+ body = VFIL_readfile(NULL, av[1], &len);
+ AN(body);
+ assert(len < INT_MAX);
+ bodylen = len;
+ av++;
} else if (!strcmp(*av, "-bodylen")) {
assert(body == nullbody);
free(body);
@@ -1007,6 +1016,9 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp,
* \-body STRING
* Input STRING as body.
*
+ * \-bodyfrom FILE
+ * Same as -body but content is read from FILE.
+ *
* \-bodylen NUMBER
* Generate and input a body that is NUMBER bytes-long.
*
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index cb15ebe82..00f254b1e 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -1322,6 +1322,9 @@ cmd_sendhex(CMD_ARGS)
* Specify a body, effectively putting STRING into a DATA frame after
* the HEADER frame is sent.
*
+ * \-bodyfrom FILE (txreq, txresp)
+ * Same as ``-body`` but content is read from FILE.
+ *
* \-bodylen INT (txreq, txresp)
* Do the same thing as ``-body`` but generate an string of INT length
* for you.
@@ -1366,6 +1369,8 @@ cmd_tx11obj(CMD_ARGS)
int method_done = 1;
int path_done = 1;
int scheme_done = 1;
+ int bodylen = 0;
+ ssize_t len;
uint32_t stid = 0, pstid;
uint32_t weight = 16;
uint32_t exclusive = 0;
@@ -1510,12 +1515,23 @@ cmd_tx11obj(CMD_ARGS)
if (AV_IS("-body")) {
AZ(body);
REPLACE(body, av[1]);
+ bodylen = strlen(body);
+ f.flags &= ~END_STREAM;
+ av++;
+ }
+ else if (AV_IS("-bodyfrom")) {
+ AZ(body);
+ body = VFIL_readfile(NULL, av[1], &len);
+ AN(body);
+ assert(len < INT_MAX);
+ bodylen = len;
f.flags &= ~END_STREAM;
av++;
}
else if (AV_IS("-bodylen")) {
AZ(body);
body = synth_body(av[1], 0);
+ bodylen = strlen(body);
f.flags &= ~END_STREAM;
av++;
}else if (AV_IS("-dep")) {
@@ -1585,7 +1601,7 @@ cmd_tx11obj(CMD_ARGS)
if (!body)
return;
- INIT_FRAME(f, DATA, strlen(body), s->id, END_STREAM);
+ INIT_FRAME(f, DATA, bodylen, s->id, END_STREAM);
f.data = body;
write_frame(s->hp, &f, 1);
More information about the varnish-commit
mailing list