]> err.no Git - varnish/commitdiff
Add the HTTP subprocessor
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 12:08:11 +0000 (12:08 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 15 Jun 2008 12:08:11 +0000 (12:08 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2675 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/Makefile.am
varnish-cache/bin/varnishtest/t000.vtc
varnish-cache/bin/varnishtest/vtc.h
varnish-cache/bin/varnishtest/vtc_client.c
varnish-cache/bin/varnishtest/vtc_http.c [new file with mode: 0644]
varnish-cache/bin/varnishtest/vtc_server.c

index 09e59dd89205c12b2e8f3b83398e38707a92ab75..1fc15f48735155d91fe6998dea030cc0af654890 100644 (file)
@@ -7,6 +7,7 @@ bin_PROGRAMS =  varnishtest
 varnishtest_SOURCES = \
                vtc.c \
                vtc_client.c \
+               vtc_http.c \
                vtc_server.c \
                vtc_stats.c \
                vtc_varnish.c \
index b717e23501b797f8ffe2f7b50eeec5047ffc52d7..86c29214c9b78bf74e075cd1f41111570294fa4e 100644 (file)
@@ -3,7 +3,7 @@
 
 server s1 -listen :9080 -repeat 2 {
        rxreq
-       expect url == "/"
+       expect req.url == "/"
        txresponse -body "0123456789"
 }
 
@@ -12,8 +12,8 @@ server s1 -start
 client c1 -connect localhost:9080 {
        txreq -url "/"
        rxresponse
-       expect status == 200
-       expect length == 10
+       expect resp.status == 200
+       expect resp.length == 10
 }
 
 client c1 -run
index 916888992d43d68d39b77a8ce244bf237153991d..63d8fe35f139464e48f94faba725706b04acaf93 100644 (file)
@@ -40,3 +40,4 @@ void cmd_vcl(char **av, void *priv);
 void cmd_stats(char **av, void *priv);
 void cmd_varnish(char **av, void *priv);
 
+void http_process(const char *spec, int sock, int client);
index 22c1845cd5dcca487d34599e5cd9c32ccc85879f..b437d8be2d3b615aa970503b3f382398db87b1bb 100644 (file)
@@ -84,7 +84,7 @@ client_thread(void *priv)
        assert(fd >= 0);
        printf("#### Client %s connected to %s fd is %d\n",
            c->name, c->connect, fd);
-       sleep (1);
+       http_process(c->spec, fd, 1);
        close(fd);
        printf("### Client %s ending\n", c->name);
 
diff --git a/varnish-cache/bin/varnishtest/vtc_http.c b/varnish-cache/bin/varnishtest/vtc_http.c
new file mode 100644 (file)
index 0000000..7ad82f9
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "libvarnish.h"
+#include "miniobj.h"
+
+#include "vtc.h"
+
+
+struct http {
+       unsigned                magic;
+#define HTTP_MAGIC             0x2f02169c
+       int                     fd;
+       int                     client;
+};
+
+
+static struct cmds http_cmds[] = {
+       { "txreq",      cmd_dump },
+       { "rxreq",      cmd_dump },
+       { "txresponse", cmd_dump },
+       { "rxresponse", cmd_dump },
+       { "expect",     cmd_dump },
+       { NULL,         NULL }
+};
+
+void
+http_process(const char *spec, int sock, int client)
+{
+       struct http *hp;
+       char *s, *q;
+
+       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');
+       assert(q > s);
+       q--;
+       assert(*q == '}');
+       *q = '\0';
+       AN(s);
+       parse_string(s, http_cmds, hp);
+}
index 7d2ec5aeff58094c7892247306fa38ce648400a2..d9462d0e5daa30bcf87b1be95f5cbabd1da3ab9c 100644 (file)
@@ -88,6 +88,7 @@ server_thread(void *priv)
                l = sizeof addr_s;
                fd = accept(s->sock, addr, &l);
                printf("#### Accepted socket %d\n", fd);
+               http_process(s->spec, fd, 0);
                close(fd);
        }
        printf("### Server %s ending\n", s->name);