From 73dad22d7d55f6588c11d735561935743b99526a Mon Sep 17 00:00:00 2001 From: des Date: Tue, 4 Jul 2006 13:11:39 +0000 Subject: [PATCH] Correct the Connection header, and add ability to perform HEAD requests. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@294 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-tools/fetcher/fetcher.c | 48 ++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/varnish-tools/fetcher/fetcher.c b/varnish-tools/fetcher/fetcher.c index 12c4b571..4d73b3ce 100644 --- a/varnish-tools/fetcher/fetcher.c +++ b/varnish-tools/fetcher/fetcher.c @@ -11,11 +11,15 @@ #include #include #include +#include +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); -- 2.39.5