]> err.no Git - varnish/commitdiff
Implement http::txreq
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 12:45:53 +0000 (12:45 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 12:45:53 +0000 (12:45 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2679 d4fa192b-c00b-0410-8231-f00ffab90ce4

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

index e394f51da85b36f08a36fdc4938c2ebea727eb18..34d1777f0ef9fc268a476dc683b619bbc1d42767 100644 (file)
@@ -11,7 +11,7 @@ server s1 -listen :9080 -repeat 2 {
 server s1 -start 
 
 client c1 -connect localhost:9080 {
-       txreq -url "/"
+       txreq 
        rxresponse
        expect resp.status == 200
        expect resp.length == 10
index 28c5b7b234160be8629f1f35ff2859074f6a14cd..acb613a0dd88c592611ba6bd51885abe7e4f57c7 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "libvarnish.h"
 #include "miniobj.h"
+#include "vsb.h"
 
 #include "vtc.h"
 
@@ -44,9 +46,80 @@ struct http {
        int                     client;
 };
 
+/**********************************************************************
+ * Transmit a request
+ */
+
+static void
+cmd_http_txreq(char **av, void *priv)
+{
+       struct http *hp;
+       struct vsb *vsb;
+       const char *req = "GET";
+       const char *url = "/";
+       const char *proto = "HTTP/1.1";
+       int dohdr = 0;
+       const char *nl = "\r\n";
+       int l;
+
+       CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+       AN(hp->client);
+       assert(!strcmp(av[0], "txreq"));
+       av++;
+
+       vsb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
+
+       for(; *av != NULL; av++) {
+               if (!strcmp(*av, "-url")) {
+                       AZ(dohdr);
+                       url = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-proto")) {
+                       AZ(dohdr);
+                       proto = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-req")) {
+                       AZ(dohdr);
+                       req = av[1];
+                       av++;
+                       continue;
+               }
+               if (!strcmp(*av, "-hdr")) {
+                       if (dohdr == 0) {
+                               vsb_printf(vsb, "%s %s %s%s", 
+                                   req, url, proto, nl);
+                               dohdr = 1;
+                       }
+                       vsb_printf(vsb, "%s%s", av[1], nl);
+                       av++;
+                       continue;
+               }
+               fprintf(stderr, "Unknown http spec: %s\n", *av);
+               exit (1);
+       }
+       if (dohdr == 0) {
+               vsb_printf(vsb, "%s %s %s%s", 
+                   req, url, proto, nl);
+               dohdr = 1;
+       }
+       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);
+}
+
+/**********************************************************************
+ * Execute HTTP specifications
+ */
 
 static struct cmds http_cmds[] = {
-       { "txreq",      cmd_dump },
+       { "txreq",      cmd_http_txreq },
        { "rxreq",      cmd_dump },
        { "txresponse", cmd_dump },
        { "rxresponse", cmd_dump },
@@ -63,9 +136,6 @@ http_process(const char *spec, int sock, int client)
        ALLOC_OBJ(hp, HTTP_MAGIC);
        hp->fd = sock;
        hp->client = client;
-       (void)spec;
-       (void)sock;
-       (void)client;
 
        s = strdup(spec + 1);
        q = strchr(s, '\0');