Commit 4d3baa90 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by guillaume quintard

Write a request or response body from a stream too

parent 73d44e8b
varnishtest "Write a body to a file"
server s1 {
fatal
stream 1 {
rxreq
expect req.http.Content-Type == "text/plain"
write_body req.txt
txresp -hdr Content-Type text/plain -body response
} -run
} -start
client c1 -connect ${s1_sock} {
fatal
stream 1 {
txreq -req POST -hdr Content-Type text/plain -body request
rxresp
expect resp.http.Content-Type == "text/plain"
write_body resp.txt
} -run
} -run
server s1 -wait
shell {grep -q request req.txt}
shell {grep -q response resp.txt}
......@@ -45,6 +45,7 @@
#include "vtc_http.h"
#include "vct.h"
#include "vfil.h"
#include "vgz.h"
#include "vnum.h"
#include "vre.h"
......@@ -2467,6 +2468,28 @@ cmd_expect(CMD_ARGS)
AZ(pthread_mutex_unlock(&s->hp->mtx));
}
/* SECTION: stream.spec.write_body
*
* write_body STRING
* Same as the ``write_body`` command for HTTP/1.
*/
static void
cmd_write_body(CMD_ARGS)
{
struct stream *s;
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC);
AN(av[0]);
AN(av[1]);
AZ(av[2]);
AZ(strcmp(av[0], "write_body"));
if (VFIL_writefile(NULL, av[1], s->body, s->bodylen) != 0)
vtc_log(s->hp->vl, 0, "failed to write body: %s (%d)",
strerror(errno), errno);
}
/* SECTION: stream.spec Specification
*
* The specification of a stream follows the exact same rules as one for a
......@@ -2502,6 +2525,7 @@ static const struct cmds stream_cmds[] = {
CMD_STREAM(txrst)
CMD_STREAM(txsettings)
CMD_STREAM(txwinup)
CMD_STREAM(write_body)
/* general purpose */
CMD(barrier)
......
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