headers as unordered_map instead of unordered_multimap
I think it would be nicer when using headers if they were in a map instead of a multimap.
Ref: RFC 7230 section 3.2.2 Except for the set-cookie header it should only require appending repeat header values with commas.
Ref: RFC 6265 section 4.1.1 Since path-value and extension-av can contain commas.
HttpHeader::parse could return an object with cookies parsed separately: struct Headers { CaseInsensitiveMap fields; Cookies cookies; };
Where Cookies is an appropriate type.
Storing the cookies as specified by the cookie parameters is probably out of scope for this lib?
Also set-cookie is only in the response headers? Their could be HttpResponseHeaders::parse and HttpRequestHeaders::parse.
I'm leaning towards keeping multimap since it is the general approach, but I'm open for discussion on this.
Also, parsing cookies are a bit similar to the ContentDisposition::parse function found in utility.hpp, but it requires a slight modification to make it work (values are not encapsulated in ""). Might be that one could create a general function that would work for both cookies and content disposition.
edit: An function that parses both content-disposition and set-cookie field values have been implemented: HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse
Alternate idea: combine the non set-cookie headers automatically so that if the user isn't looking for cookies they don't need to iterate over repeat header keys.
Something like so:
auto &iter = result.find(line.substr(0, param_end));
if (iter == result.end() || iter->first == "set-cookie")
result.emplace(line.substr(0, param_end), line.substr(value_start, line.size() - value_start - 1));
else
iter->second += ", " + line.substr(value_start, line.size() - value_start - 1);
Thank you for the suggestion. One problem I can see is that the response header type, if it should support multiple set-cookie header fields, would be different from the request header type.