Respect that HTTP headers are case insensitive.

So we look for them using strcasestr instead fo strstr.

If this ever becomes a bottleneck, it can probably be optimized by only
trying to match the words right after "\r\n".
This commit is contained in:
Érico Nogueira 2021-05-21 02:23:56 -03:00
parent 552388db2d
commit 910b69f6b2
1 changed files with 3 additions and 2 deletions

View File

@ -1,3 +1,4 @@
#define _GNU_SOURCE /* strcasestr */
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
@ -99,8 +100,8 @@ size_t ssl_to_mmap(struct transmission_information ti)
if (ti.type == HTTP_CONN) {
// http headers need to be parsed for content length
const char *needle = "Content-Length: ";
char *length = strstr(st.header, needle);
const char *needle = "content-length: ";
char *length = strcasestr(st.header, needle);
if (length == NULL) {
fputs("header didn't contain content-length field\n", stderr);
rv = 0;