From b720a89d5524a964070bc3c9e9fb0053de8e298b Mon Sep 17 00:00:00 2001 From: "Jyri J. Virkki" Date: Sun, 6 Jan 2013 02:21:09 -0800 Subject: [PATCH] Fix header parsing to compare HTTP header field names case insensitively. This fixes the problem where responses get incorrectly marked as errors if the response header field name case doesn't happen to match to what is in the code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also compare connection and transfer-encoding tokens case insensitively. (Reference: RFC 2616: header field names are not case sensitive.) Co-authored-by: Stefan Bühler --- src/client.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/client.c b/src/client.c index f8875e4..dd48265 100644 --- a/src/client.c +++ b/src/client.c @@ -379,26 +379,24 @@ static uint8_t client_parse(Client *client, int size) { str = &client->buffer[client->parser_offset]; //printf("checking header: '%s'\n", str); - if (strncmp(str, "Content-Length: ", sizeof("Content-Length: ")-1) == 0) { + if (strncasecmp(str, "Content-Length: ", sizeof("Content-Length: ")-1) == 0) { /* content length header */ client->content_length = str_to_uint64(str + sizeof("Content-Length: ") - 1); - } else if (strncmp(str, "Connection: ", sizeof("Connection: ")-1) == 0) { + } else if (strncasecmp(str, "Connection: ", sizeof("Connection: ")-1) == 0) { /* connection header */ str += sizeof("Connection: ") - 1; - if (strncmp(str, "close", sizeof("close")-1) == 0) + if (strncasecmp(str, "close", sizeof("close")-1) == 0) client->keepalive = 0; - else if (strncmp(str, "Keep-Alive", sizeof("Keep-Alive")-1) == 0) - client->keepalive = client->worker->config->keep_alive; - else if (strncmp(str, "keep-alive", sizeof("keep-alive")-1) == 0) + else if (strncasecmp(str, "keep-alive", sizeof("keep-alive")-1) == 0) client->keepalive = client->worker->config->keep_alive; else return 0; - } else if (strncmp(str, "Transfer-Encoding: ", sizeof("Transfer-Encoding: ")-1) == 0) { + } else if (strncasecmp(str, "Transfer-Encoding: ", sizeof("Transfer-Encoding: ")-1) == 0) { /* transfer encoding header */ str += sizeof("Transfer-Encoding: ") - 1; - if (strncmp(str, "chunked", sizeof("chunked")-1) == 0) + if (strncasecmp(str, "chunked", sizeof("chunked")-1) == 0) client->chunked = 1; else return 0;