]> err.no Git - varnish/commitdiff
Correct the Connection header, and add ability to perform HEAD requests.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Jul 2006 13:11:39 +0000 (13:11 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Jul 2006 13:11:39 +0000 (13:11 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@294 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-tools/fetcher/fetcher.c

index 12c4b5712e3edc8b1f2e677455513a910f0455bb..4d73b3ce00444129f073e7ed87dbdba014550ac9 100644 (file)
 #include <fetch.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
+static const char HEAD[] = "HEAD";
+static const char GET[] = "GET";
+static const char *method = GET;
 static const char *req_pattern =
-"GET http://varnish-test-1.linpro.no/cgi-bin/recursor.pl?foo=%d HTTP/1.1\r\n"
+"%s /cgi-bin/recursor.pl?foo=%d HTTP/1.1\r\n"
 "Host: varnish-test-1.linpro.no\r\n"
-"Connection: keep\r\n"
+"Connection: Keep-Alive\r\n"
 "\r\n";
 
 static const char *
@@ -43,14 +47,36 @@ read_line(FILE *f)
        return (buf);
 }
 
+static void
+usage(void)
+{
+       fprintf(stderr, "usage: fetcher [-h]\n");
+       exit(1);
+}
+
 int
-main(void)
+main(int argc, char *argv[])
 {
        struct addrinfo hints, *res;
-       int clen, code, ctr, error, sd;
+       int clen, code, ctr, error, opt, sd;
        const char *line;
        FILE *f;
 
+       while ((opt = getopt(argc, argv, "h")) != -1)
+               switch (opt) {
+               case 'h':
+                       method = HEAD;
+                       break;
+               default:
+                       usage();
+               }
+
+       argc -= optind;
+       argv += optind;
+
+       if (argc != 0)
+               usage();
+
        /* connect to accelerator */
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_INET;
@@ -65,12 +91,13 @@ main(void)
                err(1, "fdopen()");
 
        for (ctr = 0; ctr < 5000; ++ctr) {
-               fprintf(stderr, "\r%d ", ctr);
 
                /* send request */
-               fprintf(f, req_pattern, ctr);
+               fprintf(f, req_pattern, method, ctr);
 #ifdef DEBUG
-               fprintf(stderr, req_pattern, ctr);
+               fprintf(stderr, req_pattern, method, ctr);
+#else
+               fprintf(stderr, "\r%d ", ctr);
 #endif
 
                /* get response header */
@@ -94,9 +121,10 @@ main(void)
                        errx(1, "no content length");
 
                /* eat contents */
-               while (clen--)
-                       if (getc(f) == EOF)
-                               errx(1, "connection prematurely closed");
+               if (method != HEAD)
+                       while (clen--)
+                               if (getc(f) == EOF)
+                                       errx(1, "connection prematurely closed");
        }
        fclose(f);