--- /dev/null
+# $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
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
*/
cmd_var_resolve(struct http *hp, char *spec)
{
char **hh, *hdr;
- int n, l;
if (!strcmp(spec, "req.request"))
return(hp->req[0]);
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);
}
}
+/**********************************************************************
+ * 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
*/
vtc_log(hp->vl, 3, "rxresp");
http_rxhdr(hp);
http_splitheader(hp, 0);
+ http_swallow_body(hp, hp->resp);
}
/**********************************************************************
vtc_log(hp->vl, 3, "rxreq");
http_rxhdr(hp);
http_splitheader(hp, 1);
+ http_swallow_body(hp, hp->req);
}
/**********************************************************************
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;
av++;
continue;
}
+ if (!strcmp(*av, "-body")) {
+ body = av[1];
+ av++;
+ continue;
+ }
fprintf(stderr, "Unknown http txreq spec: %s\n", *av);
exit (1);
}
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));