eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

Should we be using map instead of multimap for headers? #206

Closed moodboom closed 6 years ago

moodboom commented 6 years ago

Apologies, this is more of a question than actual issue, I hope that's okay.

There was an update to the code to change headers from std::map to CaseInsensitiveMultimap. That's working great to ensure that header comparisons are case-insensitive.

But my code is layered in a way that it is much more convenient to be able to change existing header values as the client request is initialized (it goes through several adjustments to set up Oauth). A multimap makes that more difficult. I changed CaseInsensitiveMultimap back to a map instead of multimap and my existing code is working great again.

I checked the spec, and it is correct that duplicate keys are allowed in the header, but with clarification that allows a workaround (providing a single key with csv values). See:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2

I found that in this lengthy discussion for a node.js issue on the same subject:

https://github.com/nodejs/node/issues/3591

So the question is, what do you think is a better choice for the end user, easier ability to change a header value, or correct support of multiple values per header key (avoiding the need to use a csv workaround)? I'm honestly not sure of my opinion, and I'm considering refactoring my code to only set header key values once.

moodboom commented 6 years ago

I refactored my code to only set headers precisely once, I'll close this.