Commit 2da4eed1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make -body automatically create a Content-Length header in txresp and txreq.

For lowerlevel syntax based tests, we can revert to send and chunked.


git-svn-id: http://www.varnish-cache.org/svn/trunk@2818 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e715d873
......@@ -8,7 +8,6 @@ server s1 -listen 127.0.0.1:9080 {
expect req.proto == HTTP/1.0
expect req.url == "/foo"
txresp -proto HTTP/1.2 -status 201 -msg Foo \
-hdr "Content-Length: 10" \
-body "987654321\n"
}
......@@ -16,7 +15,6 @@ server s1 -start
client c1 -connect 127.0.0.1:9080 {
txreq -req PUT -proto HTTP/1.0 -url /foo \
-hdr "Content-Length: 10" \
-body "123456789\n"
rxresp
expect resp.proto == HTTP/1.2
......
......@@ -5,20 +5,18 @@ test "TCP reuse"
server s1 -listen 127.0.0.1:9080 {
rxreq
expect req.url == "/1"
txresp -hdr "Content-Length: 10" -body "123456789\n"
txresp -body "123456789\n"
rxreq
expect req.url == "/2"
txresp -hdr "Content-Length: 10" -body "987654321\n"
txresp -body "987654321\n"
}
server s1 -start
client c1 -connect 127.0.0.1:9080 {
txreq -url "/1" -req "POST" \
-hdr "Content-Length: 10" -body "abcdefghi\n"
txreq -url "/1" -req "POST" -body "abcdefghi\n"
rxresp
txreq -url "/2" -req "POST" \
-hdr "Content-Length: 10" -body "ihgfedcba\n"
txreq -url "/2" -req "POST" -body "ihgfedcba\n"
rxresp
}
......
......@@ -7,15 +7,15 @@ varnish v1 -arg "-b 127.0.0.1:9080" -start
server s1 {
rxreq
expect req.http.foobar == "1"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 1" -hdr "Content-Length: 5" -body "1111\n"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 1" -body "1111\n"
rxreq
expect req.http.foobar == "2"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 2" -hdr "Content-Length: 5" -body "2222\n"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 2" -body "2222\n"
rxreq
expect req.http.foobar == "3"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 3" -hdr "Content-Length: 5" -body "3333\n"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 3" -body "3333\n"
rxreq
txresp -hdr "Vary: Foobar" -hdr "Snafu: 4" -hdr "Content-Length: 5" -body "4444\n"
txresp -hdr "Vary: Foobar" -hdr "Snafu: 4" -body "4444\n"
} -start
client c1 {
......
......@@ -5,10 +5,10 @@ test "Test simple ACL"
server s1 {
rxreq
expect req.url == "/"
txresp -hdr "Content-Length: 5" -body "1111\n"
txresp -body "1111\n"
rxreq
expect req.url == "foo"
txresp -hdr "Content-Length: 5" -body "2222\n"
txresp -body "2222\n"
} -start
varnish v1 -vcl+backend {
......
......@@ -6,7 +6,6 @@ server s1 {
rxreq
txresp \
-hdr "Date: Thu, 19 Jun 2008 21:14:49 GMT" \
-hdr "Content-Length: 7" \
-hdr "Expires: Thu, 19 Jun 2008 21:14:49 GMT" \
-hdr "Last-Modified: Sun, 27 Nov 2005 05:41:47 GMT" \
-hdr "Cache-Control: max-age =0" \
......
......@@ -359,7 +359,6 @@ cmd_http_txresp(CMD_ARGS)
const char *status = "200";
const char *msg = "Ok";
const char *body = NULL;
int dohdr = 0;
(void)cmd;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
......@@ -371,46 +370,42 @@ cmd_http_txresp(CMD_ARGS)
for(; *av != NULL; av++) {
if (!strcmp(*av, "-proto")) {
AZ(dohdr);
proto = av[1];
av++;
continue;
}
if (!strcmp(*av, "-status")) {
AZ(dohdr);
} else if (!strcmp(*av, "-status")) {
status = av[1];
av++;
continue;
}
if (!strcmp(*av, "-msg")) {
AZ(dohdr);
} else if (!strcmp(*av, "-msg")) {
msg = av[1];
av++;
continue;
}
if (!strcmp(*av, "-body")) {
body = av[1];
av++;
continue;
}
} else
break;
}
vsb_printf(hp->vsb, "%s %s %s%s", proto, status, msg, nl);
for(; *av != NULL; av++) {
if (!strcmp(*av, "-hdr")) {
if (dohdr == 0) {
vsb_printf(hp->vsb, "%s %s %s%s",
proto, status, msg, nl);
dohdr = 1;
}
vsb_printf(hp->vsb, "%s%s", av[1], nl);
av++;
continue;
}
fprintf(stderr, "Unknown http txreq spec: %s\n", *av);
exit (1);
} else
break;
}
if (dohdr == 0) {
vsb_printf(hp->vsb, "%s %s %s%s",
proto, status, msg, nl);
dohdr = 1;
for(; *av != NULL; av++) {
if (!strcmp(*av, "-body")) {
AZ(body);
body = av[1];
av++;
} else
break;
}
if (*av != NULL) {
fprintf(stderr, "Unknown http txresp spec: %s\n", *av);
exit (1);
}
if (body != NULL)
vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl);
vsb_cat(hp->vsb, nl);
if (body != NULL) {
vsb_cat(hp->vsb, body);
......@@ -456,7 +451,6 @@ cmd_http_txreq(CMD_ARGS)
const char *url = "/";
const char *proto = "HTTP/1.1";
const char *body = NULL;
int dohdr = 0;
(void)cmd;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
......@@ -468,46 +462,39 @@ cmd_http_txreq(CMD_ARGS)
for(; *av != NULL; av++) {
if (!strcmp(*av, "-url")) {
AZ(dohdr);
url = av[1];
av++;
continue;
}
if (!strcmp(*av, "-proto")) {
AZ(dohdr);
} else if (!strcmp(*av, "-proto")) {
proto = av[1];
av++;
continue;
}
if (!strcmp(*av, "-req")) {
AZ(dohdr);
} else if (!strcmp(*av, "-req")) {
req = av[1];
av++;
continue;
}
} else
break;
}
vsb_printf(hp->vsb, "%s %s %s%s", req, url, proto, nl);
for(; *av != NULL; av++) {
if (!strcmp(*av, "-hdr")) {
if (dohdr == 0) {
vsb_printf(hp->vsb, "%s %s %s%s",
req, url, proto, nl);
dohdr = 1;
}
vsb_printf(hp->vsb, "%s%s", av[1], nl);
av++;
continue;
}
} else
break;
}
for(; *av != NULL; av++) {
if (!strcmp(*av, "-body")) {
AZ(body);
body = av[1];
av++;
continue;
}
} else
break;
}
if (*av != NULL) {
fprintf(stderr, "Unknown http txreq spec: %s\n", *av);
exit (1);
}
if (dohdr == 0) {
vsb_printf(hp->vsb, "%s %s %s%s",
req, url, proto, nl);
dohdr = 1;
}
if (body != NULL)
vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl);
vsb_cat(hp->vsb, nl);
if (body != NULL) {
vsb_cat(hp->vsb, body);
......
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