From c1a0af1e288ace476910a6b9a3e78a2d5429e582 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 15 Jun 2008 12:45:53 +0000 Subject: [PATCH] Implement http::txreq git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2679 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishtest/t000.vtc | 2 +- varnish-cache/bin/varnishtest/vtc_http.c | 78 ++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/varnish-cache/bin/varnishtest/t000.vtc b/varnish-cache/bin/varnishtest/t000.vtc index e394f51d..34d1777f 100644 --- a/varnish-cache/bin/varnishtest/t000.vtc +++ b/varnish-cache/bin/varnishtest/t000.vtc @@ -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 diff --git a/varnish-cache/bin/varnishtest/vtc_http.c b/varnish-cache/bin/varnishtest/vtc_http.c index 28c5b7b2..acb613a0 100644 --- a/varnish-cache/bin/varnishtest/vtc_http.c +++ b/varnish-cache/bin/varnishtest/vtc_http.c @@ -30,9 +30,11 @@ #include #include #include +#include #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'); -- 2.39.5