summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJyri J. Virkki <jyri@virkki.com>2013-01-06 02:21:09 -0800
committerStefan Bühler <stbuehler@web.de>2013-01-07 15:08:05 +0100
commitb720a89d5524a964070bc3c9e9fb0053de8e298b (patch)
treebf604ea51eccc21211454c83d317cb42e63cf506
parent1bdbe4003c8d7d61568ed45548fccf354ab19018 (diff)
downloadweighttp-b720a89d5524a964070bc3c9e9fb0053de8e298b.tar.gz
weighttp-b720a89d5524a964070bc3c9e9fb0053de8e298b.zip
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. 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 <stbuehler@web.de>
-rw-r--r--src/client.c14
1 files 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;