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