Make http header parsing case insensitive (#13267)

This commit is contained in:
Sage 2021-11-21 13:43:58 -06:00 committed by GitHub
parent 71b30d7846
commit 85a256e2cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -130,6 +130,25 @@ static INLINE bool string_is_equal_case_insensitive(const char *a,
return (result == 0);
}
static INLINE bool string_starts_with_case_insensitive(const char *str,
const char *prefix)
{
int result = 0;
const unsigned char *p1 = (const unsigned char*)str;
const unsigned char *p2 = (const unsigned char*)prefix;
if (!str || !prefix)
return false;
if (p1 == p2)
return true;
while ((result = tolower (*p1++) - tolower (*p2)) == 0)
if (*p2++ == '\0')
break;
return (result == 0 || *p2 == '\0');
}
char *string_to_upper(char *s);
char *string_to_lower(char *s);

View File

@ -898,14 +898,13 @@ bool net_http_update(struct http_t *state, size_t* progress, size_t* total)
}
else
{
if (!strncmp(state->data, "Content-Length: ",
STRLEN_CONST("Content-Length: ")))
if (string_starts_with_case_insensitive(state->data, "Content-Length: "))
{
state->bodytype = T_LEN;
state->len = strtol(state->data +
STRLEN_CONST("Content-Length: "), NULL, 10);
}
if (string_is_equal(state->data, "Transfer-Encoding: chunked"))
if (string_is_equal_case_insensitive(state->data, "Transfer-Encoding: chunked"))
state->bodytype = T_CHUNK;
/* TODO: save headers somewhere */