From ae7a043678c92503b3c09d6f18a689692b770f60 Mon Sep 17 00:00:00 2001 From: Will Date: Sun, 10 Mar 2013 16:24:27 +0900 Subject: [PATCH] allow Host header to be overridden with -H --- src/wrk.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/wrk.c b/src/wrk.c index 0669b80..109745c 100644 --- a/src/wrk.c +++ b/src/wrk.c @@ -382,18 +382,24 @@ static char *extract_url_part(char *url, struct http_parser_url *parser_url, enu } static char *format_request(char *host, char *port, char *path, char **headers) { - char *req = NULL; - - aprintf(&req, "GET %s HTTP/1.1\r\n", path); - aprintf(&req, "Host: %s", host); - if (port) aprintf(&req, ":%s", port); - aprintf(&req, "\r\n"); + char *req = NULL; + char *head = NULL; for (char **h = headers; *h != NULL; h++) { - aprintf(&req, "%s\r\n", *h); + aprintf(&head, "%s\r\n", *h); + if (!strncasecmp(*h, "Host:", 5)) { + host = NULL; + port = NULL; + } } - aprintf(&req, "\r\n"); + aprintf(&req, "GET %s HTTP/1.1\r\n", path); + if (host) aprintf(&req, "Host: %s", host); + if (port) aprintf(&req, ":%s", port); + if (host) aprintf(&req, "\r\n"); + aprintf(&req, "%s\r\n", head ? head : ""); + + free(head); return req; }