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>
This commit is contained in:
Jyri J. Virkki 2013-01-06 02:21:09 -08:00 committed by Stefan Bühler
parent 1bdbe4003c
commit b720a89d55

View File

@ -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;