System/Libraries/Http: Introduce @http_concat_header()

This function will append values with existing keys to the same JSON
array for further parsing, e.g. where multiple Set-Cookie instances
are present in a response header.
This commit is contained in:
Alec Murphy
2025-10-10 11:31:57 -04:00
parent c1280e0964
commit 6673a0d777

View File

@@ -273,6 +273,29 @@ done_parsing_url:
return url;
}
U0 @http_concat_header(JsonObject* headers, U8* key, U8* value)
{
// Concatenate multiple values w/ same key to JSON array, if necessary, OR simply store the value.
JsonKey* existing_key = headers->@(key, TRUE);
JsonArray* a = NULL;
if (existing_key) {
switch (existing_key->type) {
case JSON_ARRAY:
a = existing_key->value;
break;
default:
a = Json.CreateArray(erythros_mem_task);
a->append(existing_key->value, JSON_STRING);
existing_key->value = a;
existing_key->type = JSON_ARRAY;
break;
}
a->append(value, JSON_STRING);
} else {
headers->set(key, value, JSON_STRING);
}
}
U0 @http_parse_response_headers(@http_response* resp, U8* buffer, I64 length)
{
if (!resp || !buffer || !length)
@@ -308,7 +331,7 @@ U0 @http_parse_response_headers(@http_response* resp, U8* buffer, I64 length)
key_ptr = lines[i];
value_ptr = lines[i] + j + 2;
(*StrFind("\r", value_ptr)) = NULL;
headers->set(key_ptr, value_ptr, JSON_STRING);
@http_concat_header(headers, key_ptr, value_ptr);
goto @http_next_header_line;
}
}