chenBright commented on code in PR #3606:
URL: https://github.com/apache/brpc/pull/3606#discussion_r4278835538
##########
src/brpc/http_header.cpp:
##########
@@ -136,22 +139,34 @@ std::string& HttpHeader::GetOrAddHeader(const
std::string& key) {
std::string* val = _headers.seek(key);
if (nullptr == val) {
+ const size_t old_bucket_count = _headers.bucket_count();
val = _headers.insert({ key, "" });
if (is_set_cookie) {
_first_set_cookie = val;
}
+ if (_headers.bucket_count() != old_bucket_count) {
+ RefreshFirstSetCookie();
+ }
}
return *val;
}
std::string& HttpHeader::AddHeader(const std::string& key) {
+ const size_t old_bucket_count = _headers.bucket_count();
std::string* val = _headers.insert({ key, "" });
if (IsSetCookie(key) && nullptr == _first_set_cookie) {
_first_set_cookie = val;
}
+ if (_headers.bucket_count() != old_bucket_count) {
+ RefreshFirstSetCookie();
+ }
return *val;
}
+void HttpHeader::RefreshFirstSetCookie() {
+ _first_set_cookie = _headers.seek(SET_COOKIE);
Review Comment:
`HeaderMap` does not preserve insertion order within collision chains, so
`seek(SET_COOKIE)` may select a different cookie.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]