From 261c654ca0978cdc39c9670050c307fe0065fac1 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 28 Sep 2012 17:19:00 +0100 Subject: [PATCH] HTTP/1.1: Allow multiple whitespace characters in header fields --- src/client/HTTP.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/client/HTTP.cpp b/src/client/HTTP.cpp index 71adc0284..5fc4d0862 100644 --- a/src/client/HTTP.cpp +++ b/src/client/HTTP.cpp @@ -76,6 +76,17 @@ static long http_timeout = 15; static int http_use_proxy = 0; static struct sockaddr_in http_proxy; +static char * eatwhitespace(char * s) +{ + while(*s) + { + if(!(*s == ' ' || *s == '\t')) + break; + s++; + } + return s; +} + static char *mystrdup(char *s) { char *x; @@ -351,17 +362,26 @@ static void process_header(struct http_ctx *cx, char *str) } if (!strncmp(str, "Content-Length: ", 16)) { - cx->contlen = atoi(str+16); + str = eatwhitespace(str+16); + cx->contlen = atoi(str); return; } - if (!strcmp(str, "Transfer-Encoding: chunked")) + if (!strncmp(str, "Transfer-Encoding: ", 19)) { - cx->chunked = 1; + str = eatwhitespace(str+19); + if(!strncmp(str, "chunked", 8)) + { + cx->chunked = 1; + } return; } - if (!strcmp(str, "Connection: close")) + if (!strncmp(str, "Connection: ", 12)) { - cx->cclose = 1; + str = eatwhitespace(str+12); + if(!strncmp(str, "close", 6)) + { + cx->cclose = 1; + } return; } }