r2679 - trunk/varnish-cache/bin/varnishtest

phk at projects.linpro.no phk at projects.linpro.no
Sun Jun 15 14:45:54 CEST 2008


Author: phk
Date: 2008-06-15 14:45:53 +0200 (Sun, 15 Jun 2008)
New Revision: 2679

Modified:
   trunk/varnish-cache/bin/varnishtest/t000.vtc
   trunk/varnish-cache/bin/varnishtest/vtc_http.c
Log:
Implement http::txreq



Modified: trunk/varnish-cache/bin/varnishtest/t000.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/t000.vtc	2008-06-15 12:44:10 UTC (rev 2678)
+++ trunk/varnish-cache/bin/varnishtest/t000.vtc	2008-06-15 12:45:53 UTC (rev 2679)
@@ -11,7 +11,7 @@
 server s1 -start 
 
 client c1 -connect localhost:9080 {
-	txreq -url "/"
+	txreq 
 	rxresponse
 	expect resp.status == 200
 	expect resp.length == 10

Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c	2008-06-15 12:44:10 UTC (rev 2678)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c	2008-06-15 12:45:53 UTC (rev 2679)
@@ -30,9 +30,11 @@
 #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 @@
 	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 @@
 	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');




More information about the varnish-commit mailing list