From: Giuseppe Eletto <giuseppe.eletto98@gmail.com>
To: connman@lists.linux.dev
Cc: Giuseppe Eletto <giuseppe.eletto98@gmail.com>
Subject: [PATCH 1/2] gweb: Normalize received HTTP header field names to lowercase
Date: Tue, 7 Jul 2026 11:16:44 +0200 [thread overview]
Message-ID: <20260707091645.90508-2-giuseppe.eletto98@gmail.com> (raw)
In-Reply-To: <20260707091645.90508-1-giuseppe.eletto98@gmail.com>
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 <giuseppe.eletto98@gmail.com>
---
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
next prev parent reply other threads:[~2026-07-07 9:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 9:16 [PATCH 0/2] gweb/wispr: Normalize received HTTP header field names Giuseppe Eletto
2026-07-07 9:16 ` Giuseppe Eletto [this message]
2026-07-07 9:16 ` [PATCH 2/2] wispr: Use lowercase header field names in g_web_result_get_header calls Giuseppe Eletto
2026-07-07 15:37 ` [PATCH 0/2] gweb/wispr: Normalize received HTTP header field names Grant Erickson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260707091645.90508-2-giuseppe.eletto98@gmail.com \
--to=giuseppe.eletto98@gmail.com \
--cc=connman@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox