Commit 85350eb7 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Remove pseudo headers in HTTP/2 responses from HttpResponseInfo.

As per IETF spec https://tools.ietf.org/html/rfc7540#section-8.1.2.4,
A pseudo-header is a HTTP/2 header fields beginning with ':' and it is
not H/1 header.
Not to expose these to js API, this CL removes the headers w/o
converting to H/1 compatible header.

As a side effect, DevTools will not show these headers.

Test: Manual
Fixed: 1107710
Change-Id: Ie52ebe585c2a55a661a888c71f7687fee145aa73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379438
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarBence Béky <bnc@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806027}
parent df6c16c6
......@@ -52,6 +52,13 @@ bool SpdyHeadersToHttpResponse(const spdy::SpdyHeaderBlock& headers,
raw_headers.append(status);
raw_headers.push_back('\0');
for (it = headers.begin(); it != headers.end(); ++it) {
std::string name = it->first.as_string();
DCHECK_GT(name.size(), 0u);
if (name[0] == ':') {
// https://tools.ietf.org/html/rfc7540#section-8.1.2.4
// Skip pseudo headers.
continue;
}
// For each value, if the server sends a NUL-separated
// list of values, we separate that back out into
// individual headers for each value in the list.
......@@ -64,17 +71,15 @@ bool SpdyHeadersToHttpResponse(const spdy::SpdyHeaderBlock& headers,
size_t start = 0;
size_t end = 0;
do {
raw_headers.append(name);
raw_headers.push_back(':');
end = value.find('\0', start);
std::string tval;
if (end != value.npos)
tval = value.substr(start, (end - start));
else
tval = value.substr(start);
if (it->first[0] == ':')
raw_headers.append(it->first.as_string().substr(1));
else
raw_headers.append(it->first.as_string());
raw_headers.push_back(':');
raw_headers.append(tval);
raw_headers.push_back('\0');
start = end + 1;
......
......@@ -4323,12 +4323,12 @@ TEST_F(SpdyNetworkTransactionTest, ResponseHeaders) {
base::StringPiece expected_headers[8];
} test_cases[] = {
// No extra headers.
{0, {}, 2, {"status", "200", "hello", "bye"}},
{0, {}, 1, {"hello", "bye"}},
// Comma-separated header value.
{1,
{"cookie", "val1, val2"},
3,
{"status", "200", "hello", "bye", "cookie", "val1, val2"}},
2,
{"hello", "bye", "cookie", "val1, val2"}},
// Multiple headers are preserved: they are joined with \0 separator in
// spdy::SpdyHeaderBlock.AppendValueOrAddHeader(), then split up in
// HpackEncoder, then joined with \0 separator when
......@@ -4337,14 +4337,14 @@ TEST_F(SpdyNetworkTransactionTest, ResponseHeaders) {
// HttpResponseHeaders.
{2,
{"content-encoding", "val1", "content-encoding", "val2"},
4,
{"status", "200", "hello", "bye", "content-encoding", "val1",
"content-encoding", "val2"}},
3,
{"hello", "bye", "content-encoding", "val1", "content-encoding",
"val2"}},
// Cookie header is not split up by HttpResponseHeaders.
{2,
{"cookie", "val1", "cookie", "val2"},
3,
{"status", "200", "hello", "bye", "cookie", "val1; val2"}}};
2,
{"hello", "bye", "cookie", "val1; val2"}}};
for (size_t i = 0; i < base::size(test_cases); ++i) {
SpdyTestUtil spdy_test_util;
......@@ -4445,14 +4445,11 @@ TEST_F(SpdyNetworkTransactionTest, ResponseHeadersVary) {
};
// Construct the reply.
const char** expected_res_extra_headers = test_cases[i].extra_headers[1];
int expected_res_num_headers = test_cases[i].num_headers[1];
spdy::SpdyHeaderBlock reply_headers;
AppendToHeaderBlock(test_cases[i].extra_headers[1],
test_cases[i].num_headers[1],
AppendToHeaderBlock(expected_res_extra_headers, expected_res_num_headers,
&reply_headers);
// Construct the expected header reply string before moving |reply_headers|.
std::string expected_reply =
spdy_test_util.ConstructSpdyReplyString(reply_headers);
spdy::SpdySerializedFrame frame_reply(
spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers)));
......@@ -4505,7 +4502,17 @@ TEST_F(SpdyNetworkTransactionTest, ResponseHeadersVary) {
lines.append("\n");
}
EXPECT_EQ(expected_reply, lines) << i;
// Remove ":status" and ":path" field from HTTP response.
// See SpdyHeadersToHttpResponse().
ASSERT_EQ(expected_res_extra_headers[0], spdy::kHttp2StatusHeader);
ASSERT_EQ(expected_res_extra_headers[2], spdy::kHttp2PathHeader);
ASSERT_GT(expected_res_num_headers, 1);
spdy::SpdyHeaderBlock http_reply_headers;
AppendToHeaderBlock(&expected_res_extra_headers[4],
expected_res_num_headers - 2, &http_reply_headers);
std::string expected_http_reply =
spdy_test_util.ConstructSpdyReplyString(http_reply_headers);
EXPECT_EQ(expected_http_reply, lines) << i;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment