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:
parent
1bdbe4003c
commit
b720a89d55
14
src/client.c
14
src/client.c
@ -379,26 +379,24 @@ static uint8_t client_parse(Client *client, int size) {
|
|||||||
str = &client->buffer[client->parser_offset];
|
str = &client->buffer[client->parser_offset];
|
||||||
//printf("checking header: '%s'\n", str);
|
//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 */
|
/* content length header */
|
||||||
client->content_length = str_to_uint64(str + sizeof("Content-Length: ") - 1);
|
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 */
|
/* connection header */
|
||||||
str += sizeof("Connection: ") - 1;
|
str += sizeof("Connection: ") - 1;
|
||||||
|
|
||||||
if (strncmp(str, "close", sizeof("close")-1) == 0)
|
if (strncasecmp(str, "close", sizeof("close")-1) == 0)
|
||||||
client->keepalive = 0;
|
client->keepalive = 0;
|
||||||
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 if (strncmp(str, "keep-alive", sizeof("keep-alive")-1) == 0)
|
|
||||||
client->keepalive = client->worker->config->keep_alive;
|
client->keepalive = client->worker->config->keep_alive;
|
||||||
else
|
else
|
||||||
return 0;
|
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 */
|
/* transfer encoding header */
|
||||||
str += sizeof("Transfer-Encoding: ") - 1;
|
str += sizeof("Transfer-Encoding: ") - 1;
|
||||||
|
|
||||||
if (strncmp(str, "chunked", sizeof("chunked")-1) == 0)
|
if (strncasecmp(str, "chunked", sizeof("chunked")-1) == 0)
|
||||||
client->chunked = 1;
|
client->chunked = 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user