From e590a1b21013ec62fad642faa14736508bc79ce1 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 26 Jun 2008 09:45:29 +0000 Subject: [PATCH] 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: svn+ssh://projects.linpro.no/svn/varnish/trunk@2818 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishtest/tests/a00006.vtc | 2 - .../bin/varnishtest/tests/a00007.vtc | 10 +- .../bin/varnishtest/tests/c00004.vtc | 8 +- .../bin/varnishtest/tests/c00005.vtc | 4 +- .../bin/varnishtest/tests/r00255.vtc | 1 - varnish-cache/bin/varnishtest/vtc_http.c | 97 ++++++++----------- 6 files changed, 52 insertions(+), 70 deletions(-) diff --git a/varnish-cache/bin/varnishtest/tests/a00006.vtc b/varnish-cache/bin/varnishtest/tests/a00006.vtc index 6af785a4..29d1e164 100644 --- a/varnish-cache/bin/varnishtest/tests/a00006.vtc +++ b/varnish-cache/bin/varnishtest/tests/a00006.vtc @@ -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 diff --git a/varnish-cache/bin/varnishtest/tests/a00007.vtc b/varnish-cache/bin/varnishtest/tests/a00007.vtc index 5040ae98..e9d8eecf 100644 --- a/varnish-cache/bin/varnishtest/tests/a00007.vtc +++ b/varnish-cache/bin/varnishtest/tests/a00007.vtc @@ -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 } diff --git a/varnish-cache/bin/varnishtest/tests/c00004.vtc b/varnish-cache/bin/varnishtest/tests/c00004.vtc index 62780bb6..ea712102 100644 --- a/varnish-cache/bin/varnishtest/tests/c00004.vtc +++ b/varnish-cache/bin/varnishtest/tests/c00004.vtc @@ -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 { diff --git a/varnish-cache/bin/varnishtest/tests/c00005.vtc b/varnish-cache/bin/varnishtest/tests/c00005.vtc index ea0f4c1c..3edd216b 100644 --- a/varnish-cache/bin/varnishtest/tests/c00005.vtc +++ b/varnish-cache/bin/varnishtest/tests/c00005.vtc @@ -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 { diff --git a/varnish-cache/bin/varnishtest/tests/r00255.vtc b/varnish-cache/bin/varnishtest/tests/r00255.vtc index 0c757a98..67b01980 100644 --- a/varnish-cache/bin/varnishtest/tests/r00255.vtc +++ b/varnish-cache/bin/varnishtest/tests/r00255.vtc @@ -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" \ diff --git a/varnish-cache/bin/varnishtest/vtc_http.c b/varnish-cache/bin/varnishtest/vtc_http.c index 7d02a0fe..c9eb72f8 100644 --- a/varnish-cache/bin/varnishtest/vtc_http.c +++ b/varnish-cache/bin/varnishtest/vtc_http.c @@ -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); -- 2.39.5