From bfce7fc9a20149e6c382a244c429813719f54f0e Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 15 Jun 2008 12:08:11 +0000 Subject: [PATCH] Add the HTTP subprocessor git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2675 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishtest/Makefile.am | 1 + varnish-cache/bin/varnishtest/t000.vtc | 6 +- varnish-cache/bin/varnishtest/vtc.h | 1 + varnish-cache/bin/varnishtest/vtc_client.c | 2 +- varnish-cache/bin/varnishtest/vtc_http.c | 76 ++++++++++++++++++++++ varnish-cache/bin/varnishtest/vtc_server.c | 1 + 6 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/vtc_http.c diff --git a/varnish-cache/bin/varnishtest/Makefile.am b/varnish-cache/bin/varnishtest/Makefile.am index 09e59dd8..1fc15f48 100644 --- a/varnish-cache/bin/varnishtest/Makefile.am +++ b/varnish-cache/bin/varnishtest/Makefile.am @@ -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 \ diff --git a/varnish-cache/bin/varnishtest/t000.vtc b/varnish-cache/bin/varnishtest/t000.vtc index b717e235..86c29214 100644 --- a/varnish-cache/bin/varnishtest/t000.vtc +++ b/varnish-cache/bin/varnishtest/t000.vtc @@ -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 diff --git a/varnish-cache/bin/varnishtest/vtc.h b/varnish-cache/bin/varnishtest/vtc.h index 91688899..63d8fe35 100644 --- a/varnish-cache/bin/varnishtest/vtc.h +++ b/varnish-cache/bin/varnishtest/vtc.h @@ -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); diff --git a/varnish-cache/bin/varnishtest/vtc_client.c b/varnish-cache/bin/varnishtest/vtc_client.c index 22c1845c..b437d8be 100644 --- a/varnish-cache/bin/varnishtest/vtc_client.c +++ b/varnish-cache/bin/varnishtest/vtc_client.c @@ -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 index 00000000..7ad82f9b --- /dev/null +++ b/varnish-cache/bin/varnishtest/vtc_http.c @@ -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 +#include +#include + +#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); +} diff --git a/varnish-cache/bin/varnishtest/vtc_server.c b/varnish-cache/bin/varnishtest/vtc_server.c index 7d2ec5ae..d9462d0e 100644 --- a/varnish-cache/bin/varnishtest/vtc_server.c +++ b/varnish-cache/bin/varnishtest/vtc_server.c @@ -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); -- 2.39.5