[PATCH 1/2] gweb: Normalize received HTTP header field names to lowercase
Giuseppe Eletto <[email protected]> Tue, 7 Jul 2026 11:16:44 +0200
| Newsgroups | dev.linux.lists.connman |
|---|---|
| Message-ID | <[email protected]> |
Modern HTTP servers, including HTTP/2 and HTTP/3 backends acting as proxies, commonly send header field names in lowercase. While RFC 9110 Section 5.1 defines field names as case-insensitive, connman was performing case-sensitive hash table lookups against fixed mixed-case strings, causing lookups to silently fail when the server used lowercase names. Normalize incoming response header field names to lowercase at parse time so that lookups succeed regardless of the case used by the server. - add_header_field: use g_ascii_strdown() instead of g_strdup() to normalize the key before inserting it into the hash table - received_data_continue: look up "transfer-encoding" in lowercase to match the normalized store - g_web_result_get_header: scan the caller-supplied name for uppercase characters and normalize with g_ascii_strdown() only when needed Outgoing request headers are left in mixed case. HTTP/1.1 requires that servers recognize header field names regardless of case, so no change is needed on the sending side. Signed-off-by: Giuseppe Eletto <[email protected]> --- gweb/gweb.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gweb/gweb.c b/gweb/gweb.c index 0a87da64..26d18544 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -1201,7 +1201,7 @@ static void add_header_field(struct web_session *session) *pos = '\0'; pos++; - key = g_strdup(str); + key = g_ascii_strdown(str, -1); /* remove preceding white spaces */ while (*pos == ' ') @@ -1390,7 +1390,7 @@ static bool received_data_continue(struct web_session *session, session->header_done = true; val = g_hash_table_lookup(session->result.headers, - "Transfer-Encoding"); + "transfer-encoding"); if (val) { val = g_strrstr(val, "chunked"); if (val) { @@ -2789,13 +2789,26 @@ bool g_web_result_get_chunk(GWebResult *result, bool g_web_result_get_header(GWebResult *result, const char *header, const char **value) { + const char *p; + gchar *lower = NULL; + if (!result) return false; if (!value) return false; - *value = g_hash_table_lookup(result->headers, header); + p = header; + while (*p && !g_ascii_isupper(*p)) + p++; + + if (!*p) { + *value = g_hash_table_lookup(result->headers, header); + } else { + lower = g_ascii_strdown(header, -1); + *value = g_hash_table_lookup(result->headers, lower); + g_free(lower); + } if (!*value) return false; -- 2.50.1