From 910b69f6b2c8243cd75cd13bb24af0a1b017d20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Fri, 21 May 2021 02:23:56 -0300 Subject: [PATCH] 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". --- files.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/files.c b/files.c index cc18c79..c2863aa 100644 --- a/files.c +++ b/files.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE /* strcasestr */ #include #include #include @@ -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;