r2747 - in trunk/varnish-cache/bin/varnishtest: . tests
phk at projects.linpro.no
phk at projects.linpro.no
Fri Jun 20 17:26:03 CEST 2008
Author: phk
Date: 2008-06-20 17:26:02 +0200 (Fri, 20 Jun 2008)
New Revision: 2747
Added:
trunk/varnish-cache/bin/varnishtest/tests/a00006.vtc
Modified:
trunk/varnish-cache/bin/varnishtest/vtc_http.c
Log:
More support for message bodies
Added: trunk/varnish-cache/bin/varnishtest/tests/a00006.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/a00006.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/a00006.vtc 2008-06-20 15:26:02 UTC (rev 2747)
@@ -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
Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-06-20 14:51:51 UTC (rev 2746)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-06-20 15:26:02 UTC (rev 2747)
@@ -59,6 +59,28 @@
};
/**********************************************************************
+ * 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 @@
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 @@
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);
}
@@ -215,6 +230,33 @@
/**********************************************************************
+ * 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 @@
vtc_log(hp->vl, 3, "rxresp");
http_rxhdr(hp);
http_splitheader(hp, 0);
+ http_swallow_body(hp, hp->resp);
}
/**********************************************************************
@@ -381,6 +424,7 @@
vtc_log(hp->vl, 3, "rxreq");
http_rxhdr(hp);
http_splitheader(hp, 1);
+ http_swallow_body(hp, hp->req);
}
/**********************************************************************
@@ -395,6 +439,7 @@
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 @@
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 @@
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));
More information about the varnish-commit
mailing list