]> err.no Git - varnish/commitdiff
More support for message bodies
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 15:26:02 +0000 (15:26 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 20 Jun 2008 15:26:02 +0000 (15:26 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2747 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/tests/a00006.vtc [new file with mode: 0644]
varnish-cache/bin/varnishtest/vtc_http.c

diff --git a/varnish-cache/bin/varnishtest/tests/a00006.vtc b/varnish-cache/bin/varnishtest/tests/a00006.vtc
new file mode 100644 (file)
index 0000000..9766198
--- /dev/null
@@ -0,0 +1,37 @@
+# $Id$
+
+test "dual shared client HTTP transactions"
+
+server s1 -listen :9080 {
+       rxreq
+       expect req.request == PUT
+       expect req.proto == HTTP/1.0
+       expect req.url == "/foo"
+       txresp -proto HTTP/1.2 -status 201 -msg Foo \
+               -hdr "Length: 10" \
+               -body "987654321\n"
+}
+
+server s1 -start 
+
+client c1 -connect localhost:9080 {
+       txreq -req PUT -proto HTTP/1.0 -url /foo \
+               -hdr "Length: 10" \
+               -body "123456789\n"
+       rxresp
+       expect resp.proto == HTTP/1.2
+       expect resp.status == 201
+       expect resp.msg == Foo
+}
+
+client c1 -run
+
+client c1 -connect localhost:9081 {
+       txreq 
+       rxresp
+       expect resp.proto == HTTP/1.1
+       expect resp.status == 200
+       expect resp.msg == Ok
+}
+
+server s1 -wait
index 10223b90f7943c243b80003a3e5d49832a04ef5c..e7f8163e42a912fed7c4de9393e4903dde2890e1 100644 (file)
@@ -58,6 +58,28 @@ struct http {
        char                    *resp[MAX_HDR];
 };
 
+/**********************************************************************
+ * find header
+ */
+
+static char *
+http_find_header(char **hh, const char *hdr)
+{
+       int n, l;
+       char *r;
+
+       l = strlen(hdr);
+
+       for (n = 3; hh[n] != NULL; n++) {
+               if (strncasecmp(hdr, hh[n], l) || hh[n][l] != ':')
+                       continue;
+               for (r = hh[n] + l + 1; vct_issp(*r); r++)
+                       continue;
+               return (r);
+       }
+       return (NULL);
+}
+
 /**********************************************************************
  * Expect
  */
@@ -66,7 +88,6 @@ static char *
 cmd_var_resolve(struct http *hp, char *spec)
 {
        char **hh, *hdr;
-       int n, l;
 
        if (!strcmp(spec, "req.request"))
                return(hp->req[0]);
@@ -88,15 +109,9 @@ cmd_var_resolve(struct http *hp, char *spec)
                hdr = spec + 10;
        } else
                return (spec);
-       l = strlen(hdr);
-       for (n = 3; hh[n] != NULL; n++) {
-               if (strncasecmp(hdr, hh[n], l) || hh[n][l] != ':')
-                       continue;
-               hdr = hh[n] + l + 1;
-               while (vct_issp(*hdr))
-                       hdr++;
+       hdr = http_find_header(hh, hdr);
+       if (hdr != NULL)
                return (hdr);
-       }
        return (spec);
 }
 
@@ -214,6 +229,33 @@ http_splitheader(struct http *hp, int req)
 }
 
 
+/**********************************************************************
+ * Swallow a HTTP message body
+ */
+
+static void
+http_swallow_body(struct http *hp, char **hh)
+{
+       char *p, b[BUFSIZ + 1];
+       int l, i;
+       
+
+       p = http_find_header(hh, "length");
+       if (p == NULL)
+               return;
+       l = strtoul(p, NULL, 0);
+       while (l > 0) {
+               i = sizeof b - 1;
+               if (i > l)
+                       i = l;
+               i = read(hp->fd, b, i);
+               assert(i > 0);
+               b[i] = '\0';
+               vtc_dump(hp->vl, 4, "body", b);
+               l -= i;
+       }
+}
+
 /**********************************************************************
  * Receive a HTTP protocol header
  */
@@ -279,6 +321,7 @@ cmd_http_rxresp(char **av, void *priv)
        vtc_log(hp->vl, 3, "rxresp");
        http_rxhdr(hp);
        http_splitheader(hp, 0);
+       http_swallow_body(hp, hp->resp);
 }
 
 /**********************************************************************
@@ -381,6 +424,7 @@ cmd_http_rxreq(char **av, void *priv)
        vtc_log(hp->vl, 3, "rxreq");
        http_rxhdr(hp);
        http_splitheader(hp, 1);
+       http_swallow_body(hp, hp->req);
 }
 
 /**********************************************************************
@@ -395,6 +439,7 @@ cmd_http_txreq(char **av, void *priv)
        const char *req = "GET";
        const char *url = "/";
        const char *proto = "HTTP/1.1";
+       const char *body = NULL;
        int dohdr = 0;
        const char *nl = "\r\n";
        int l;
@@ -435,6 +480,11 @@ cmd_http_txreq(char **av, void *priv)
                        av++;
                        continue;
                }
+               if (!strcmp(*av, "-body")) {
+                       body = av[1];
+                       av++;
+                       continue;
+               }
                fprintf(stderr, "Unknown http txreq spec: %s\n", *av);
                exit (1);
        }
@@ -444,6 +494,10 @@ cmd_http_txreq(char **av, void *priv)
                dohdr = 1;
        }
        vsb_cat(vsb, nl);
+       if (body != NULL) {
+               vsb_cat(vsb, body);
+               vsb_cat(vsb, nl);
+       }
        vsb_finish(vsb);
        AZ(vsb_overflowed(vsb));
        vtc_dump(hp->vl, 4, NULL, vsb_data(vsb));