]> err.no Git - varnish/commitdiff
Stuff we use for testing.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Jul 2006 12:01:44 +0000 (12:01 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Jul 2006 12:01:44 +0000 (12:01 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@292 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-tools/fetcher/Makefile [new file with mode: 0644]
varnish-tools/fetcher/fetcher.c [new file with mode: 0644]
varnish-tools/recursor/recursor.pl [new file with mode: 0755]

diff --git a/varnish-tools/fetcher/Makefile b/varnish-tools/fetcher/Makefile
new file mode 100644 (file)
index 0000000..eb9aea0
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# $Id$
+#
+
+PROG    = fetcher
+WARNS  ?= 6
+MAN     =
+
+.include <bsd.prog.mk>
diff --git a/varnish-tools/fetcher/fetcher.c b/varnish-tools/fetcher/fetcher.c
new file mode 100644 (file)
index 0000000..b4d61ce
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <err.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <fetch.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const char *req_pattern =
+"GET http://varnish-test-1.linpro.no/cgi-bin/recursor.pl?foo=%d HTTP/1.1\r\n"
+"Host: varnish-test-1.linpro.no\r\n"
+"Connection: keep\r\n"
+"\r\n";
+
+static const char *
+read_line(FILE *f)
+{
+       static char *buf;
+       static size_t bufsz;
+       const char *line;
+       size_t len;
+
+       if ((line = fgetln(f, &len)) == NULL)
+               return (NULL);
+       while (len && (line[len - 1] == '\r' || line[len - 1] == '\n'))
+               --len;
+       if (bufsz < len + 1) {
+               bufsz = len * 2;
+               if ((buf = realloc(buf, bufsz)) == NULL)
+                       err(1, "realloc()");
+       }
+       memcpy(buf, line, len);
+       buf[len] = '\0';
+#ifdef DEBUG
+       fprintf(stderr, "<<< [%s]\n", buf);
+#endif
+       return (buf);
+}
+
+int
+main(void)
+{
+       struct addrinfo hints, *res;
+       int clen, code, ctr, error, sd;
+       const char *line;
+       FILE *f;
+
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family = AF_INET;
+       hints.ai_socktype = SOCK_STREAM;
+       if ((error = getaddrinfo("varnish-test-2.linpro.no", "http", &hints, &res)) != 0)
+               errx(1, "%s", gai_strerror(error));
+       if ((sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0)
+               err(1, "socket()");
+       if (connect(sd, res->ai_addr, res->ai_addrlen) < 0)
+               err(1, "connect()");
+       if ((f = fdopen(sd, "w+")) == NULL)
+               err(1, "fdopen()");
+       for (ctr = 0; ctr < 5000; ++ctr) {
+               fprintf(stderr, "\r%d ", ctr);
+#ifdef DEBUG
+               fprintf(stderr, req_pattern, ctr);
+#endif
+               fprintf(f, req_pattern, ctr);
+
+               /* get response header */
+               if ((line = read_line(f)) == NULL)
+                       errx(1, "protocol error");
+               if (sscanf(line, "HTTP/%*d.%*d %d %*s", &code) != 1)
+                       errx(1, "protocol error");
+               if (code != 200)
+                       errx(1, "code %d", code);
+
+               /* get content-length */
+               clen = -1;
+               for (;;) {
+                       if ((line = read_line(f)) == NULL)
+                               errx(1, "protocol error");
+                       if (line[0] == '\0')
+                               break;
+                       sscanf(line, "Content-Length: %d\n", &clen);
+               }
+               if (clen == -1)
+                       errx(1, "no content length");
+
+               /* eat contents */
+               while (clen--)
+                       if (getc(f) == EOF)
+                               errx(1, "connection prematurely closed");
+       }
+       fclose(f);
+       exit(0);
+}
diff --git a/varnish-tools/recursor/recursor.pl b/varnish-tools/recursor/recursor.pl
new file mode 100755 (executable)
index 0000000..ad5f557
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/local/bin/perl -w
+#
+# $Id$
+#
+
+use strict;
+use CGI;
+
+my $q = new CGI;
+
+my $foo = int($q->param('foo'));
+my $i = ($foo * 2) % 5000;
+my $j = ($foo * 2 + 1) % 5000;
+
+print $q->header(-expires=>'+60m');
+
+print "<h1>Page $foo</h1>\n";
+print "<p><a href=\"/cgi-bin/recursor.pl?foo=$i\">Link $i</a></p>\n";
+print "<p><a href=\"/cgi-bin/recursor.pl?foo=$j\">Link $j</a></p>\n";