Commit eec47a70 authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

SignedExchangeHandler: Derive mime_type and charset from Content-Type header

Bug: 803774
Change-Id: I3d2a71beed193949a0dd13e1ed347ff61df4dc76
Reviewed-on: https://chromium-review.googlesource.com/965725Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543650}
parent 921731ea
......@@ -323,9 +323,8 @@ void SignedExchangeHandler::OnCertVerifyComplete(int result) {
network::ResourceResponseHead response_head;
response_head.headers = header_->BuildHttpResponseHeaders();
// TODO(https://crbug.com/803774): |mime_type| should be derived from
// "Content-Type" header.
response_head.mime_type = "text/html";
response_head.headers->GetMimeTypeAndCharset(&response_head.mime_type,
&response_head.charset);
std::string mi_header_value;
if (!response_head.headers->EnumerateHeader(nullptr, kMiHeader,
......
......@@ -195,6 +195,8 @@ TEST_P(SignedExchangeHandlerTest, Simple) {
ASSERT_TRUE(read_header());
EXPECT_EQ(net::OK, error());
EXPECT_EQ(200, resource_response().headers->response_code());
EXPECT_EQ("text/html", resource_response().mime_type);
EXPECT_EQ("utf-8", resource_response().charset);
std::string payload;
int rv = ReadPayloadStream(&payload);
......@@ -205,6 +207,29 @@ TEST_P(SignedExchangeHandlerTest, Simple) {
EXPECT_EQ(rv, static_cast<int>(expected_payload.size()));
}
TEST_P(SignedExchangeHandlerTest, MimeType) {
mock_cert_verifier_->set_default_result(net::OK);
std::string contents = GetTestFileContents("test.example.org_hello.txt.htxg");
source_->AddReadResult(contents.data(), contents.size(), net::OK, GetParam());
source_->AddReadResult(nullptr, 0, net::OK, GetParam());
WaitForHeader();
ASSERT_TRUE(read_header());
EXPECT_EQ(net::OK, error());
EXPECT_EQ(200, resource_response().headers->response_code());
EXPECT_EQ("text/plain", resource_response().mime_type);
EXPECT_EQ("iso-8859-1", resource_response().charset);
std::string payload;
int rv = ReadPayloadStream(&payload);
std::string expected_payload = GetTestFileContents("hello.txt");
EXPECT_EQ(payload, expected_payload);
EXPECT_EQ(rv, static_cast<int>(expected_payload.size()));
}
TEST_P(SignedExchangeHandlerTest, ParseError) {
const uint8_t data[] = {0x00, 0x00, 0x01, 0x00};
source_->AddReadResult(reinterpret_cast<const char*>(data), sizeof(data),
......
......@@ -56,3 +56,14 @@ gen-signedexchange \
-privateKey /tmp/wildcard_example.org.private.pem \
-o test.example.com_invalid_test.htxg \
-miRecordSize 100
gen-signedexchange \
-uri https://test.example.org/hello.txt \
-status 200 \
-content hello.txt \
-certificate /tmp/wildcard_example.org.public.pem \
-certUrl https://cert.example.org/cert.msg \
-validityUrl https://cert.example.org/resource.validity.msg \
-privateKey /tmp/wildcard_example.org.private.pem \
-responseHeader 'Content-Type: text/plain; charset=iso-8859-1' \
-o test.example.org_hello.txt.htxg
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