diff --git a/System/Libraries/Http.HC b/System/Libraries/Http.HC index 66fbad6..98c8cc5 100644 --- a/System/Libraries/Http.HC +++ b/System/Libraries/Http.HC @@ -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; } }