Replace the HTTP header maps with glz::http_headers - #2718
Open
annihilatorq wants to merge 9 commits into
Open
Conversation
BREAKING CHANGE: request::headers is now glz::http_headers instead of std::unordered_map<std::string, std::string>. Names keep the casing they arrived with instead of being lowercased, and a repeated field no longer overwrites the one before it. Lookups stay case-insensitive.
BREAKING CHANGE: response::response_headers is now glz::http_headers, along with every header parameter on http_client and the streaming interfaces. Response names keep the casing they were given, so content_type() writes "Content-Type" rather than "content-type".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the net stack to glz::http_headers (#2709).
Rewriting the header lookups for the new container resulted in fixing two WebSocket bugs.
glz::http_headerskeeps repeated field names instead of overwriting them, and its.contains_token()replaced the hand-rolled substring and prefix comparisons, so every lookup had to be revisited, and both were found there.WebSocket implementation bugs
1 - the handshake response check never compared a full field name. The code used a comparison like this:
strncasecmp(name.c_str(), "Upgrade", 7)for the headers "Upgrade", "Connection" and "Sec-WebSocket-Accept" comparing the first N bytes usingstrncasecmp, where N is the length of the expected header name. The problem is that this approach would accept headers such as "Connection-Something" as valid because the name starts with "Connection", and so on with other headers listed previously.Example - the old client accepted this response even though the server never sent an
Upgradefield:2 - the client is allowed to send a list-based field not as a comma-separated list, but as separate header fields separated by CRLF. The previous issue was that
std::unordered_mapused a "last-wins" approach, thereby discarding one of the values for that header. In such cases, user could only hope that the last header received contained the required token ("Connection: Upgrade") as the header-field value.Example - the old server refused this valid request because
keep-alivearrived last: