Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use AppendHeader for http2 #2387

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/brpc/policy/http2_rpc_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,7 @@ int H2StreamContext::ConsumeHeaders(butil::IOBufBytesIterator& it) {
strcmp(name + 1, /*c*/"ontent-type") == 0) {
h.set_content_type(pair.value);
} else {
// TODO: AppendHeader?
h.SetHeader(pair.name, pair.value);
h.AppendHeader(pair.name, pair.value);
}

if (FLAGS_http_verbose) {
Expand Down
2 changes: 1 addition & 1 deletion test/brpc_http_rpc_protocol_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ TEST_F(HttpTest, http2_header_after_data) {
ASSERT_EQ(res_header.content_type(), "application/proto");
// Check overlapped header is overwritten by the latter.
const std::string* user_defined1 = res_header.GetHeader("user-defined1");
ASSERT_EQ(*user_defined1, "overwrite-a");
ASSERT_EQ(*user_defined1, "a,overwrite-a");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original test case was written as "overwrite-a", was it expected to be overwritten? Changing the behavior here may not conform to the previous design.

Copy link
Contributor Author

@lhsoft lhsoft Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case is http2_header_after_data.
For http2, according to the rfc , it shouldn't be expected to be overwritten.
The grpc use map[string][]string for header:

md := metadata.Pairs(
    "key1", "val1",
    "key1", "val1-2", // "key1" will have map value []string{"val1", "val1-2"}
    "key2", "val2",
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why it was designed to overwrite before? @zyearn

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RFC doesn't mention overwritten. It says: Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)].

In brpc implementation, if the incoming header is in the format of "key:value1,value2,value3", brpc won't overwrite cases like this. But combining headers seems reasonable otherwise the previous header would be lost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

const std::string* user_defined2 = res_header.GetHeader("user-defined2");
ASSERT_EQ(*user_defined2, "b");
}
Expand Down
Loading