]> err.no Git - varnish/commitdiff
Add http txresponse
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 13:16:18 +0000 (13:16 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 13:16:18 +0000 (13:16 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2681 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/t000.vtc
varnish-cache/bin/varnishtest/vtc_http.c

index 34d1777f0ef9fc268a476dc683b619bbc1d42767..492873ad30db08c02c0c3ebdfe4083bfb42c9c09 100644 (file)
@@ -5,14 +5,14 @@
 server s1 -listen :9080 -repeat 2 {
        rxreq
        expect req.url == "/"
-       txresponse -body "0123456789"
+       txresp -body "0123456789"
 }
 
 server s1 -start 
 
 client c1 -connect localhost:9080 {
        txreq 
-       rxresponse
+       rxresp
        expect resp.status == 200
        expect resp.length == 10
 }
index 38388f4194a198c593d42a64883946baea4707dd..b233bd3673350281d47955aa33731ff7d8ae8a87 100644 (file)
@@ -109,7 +109,7 @@ cmd_http_rxresp(char **av, void *priv)
 
        CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
        AN(hp->client);
-       assert(!strcmp(av[0], "rxresponse"));
+       assert(!strcmp(av[0], "rxresp"));
        av++;
 
        for(; *av != NULL; av++) {
@@ -120,6 +120,84 @@ cmd_http_rxresp(char **av, void *priv)
        hp->resp = hp->rxbuf;
 }
 
+/**********************************************************************
+ * Transmit a response
+ */
+
+static void
+cmd_http_txresp(char **av, void *priv)
+{
+       struct http *hp;
+       struct vsb *vsb;
+       const char *proto = "HTTP/1.1";
+       const char *status = "200";
+       const char *msg = "Ok";
+       const char *body = NULL;
+       int dohdr = 0;
+       const char *nl = "\r\n";
+       int l;
+
+       CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+       AZ(hp->client);
+       assert(!strcmp(av[0], "txresp"));
+       av++;
+
+       vsb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
+
+       for(; *av != NULL; av++) {
+               if (!strcmp(*av, "-proto")) {
+                       AZ(dohdr);
+                       proto = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-status")) {
+                       AZ(dohdr);
+                       status = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-msg")) {
+                       AZ(dohdr);
+                       msg = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-body")) {
+                       body = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-hdr")) {
+                       if (dohdr == 0) {
+                               vsb_printf(vsb, "%s %s %s%s", 
+                                   proto, status, msg, nl);
+                               dohdr = 1;
+                       }
+                       vsb_printf(vsb, "%s%s", av[1], nl);
+                       av++;
+                       continue;
+               }
+               fprintf(stderr, "Unknown http txreq spec: %s\n", *av);
+               exit (1);
+       }
+       if (dohdr == 0) {
+               vsb_printf(vsb, "%s %s %s%s", 
+                   proto, status, msg, nl);
+               dohdr = 1;
+       }
+       vsb_cat(vsb, nl);
+       if (body != NULL) {
+               vsb_cat(vsb, body);
+               vsb_cat(vsb, nl);
+       }
+       vsb_finish(vsb);
+       AZ(vsb_overflowed(vsb));
+       l = write(hp->fd, vsb_data(vsb), vsb_len(vsb));
+       assert(l == vsb_len(vsb));
+       vsb_delete(vsb);
+}
+
 /**********************************************************************
  * Receive a request
  */
@@ -217,8 +295,8 @@ cmd_http_txreq(char **av, void *priv)
 static struct cmds http_cmds[] = {
        { "txreq",      cmd_http_txreq },
        { "rxreq",      cmd_http_rxreq },
-       { "txresponse", cmd_dump },
-       { "rxresponse", cmd_http_rxresp },
+       { "txresp",     cmd_http_txresp },
+       { "rxresp",     cmd_http_rxresp },
        { "expect",     cmd_dump },
        { NULL,         NULL }
 };