OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 16661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16672 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16672 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16673 HttpRequestHeaders headers; | 16673 HttpRequestHeaders headers; |
16674 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16674 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16675 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16675 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16676 } | 16676 } |
16677 #endif // !defined(OS_IOS) | 16677 #endif // !defined(OS_IOS) |
16678 | 16678 |
16679 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, | 16679 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
16680 const std::string& accept_encoding, | 16680 const std::string& accept_encoding, |
16681 const std::string& content_encoding, | 16681 const std::string& content_encoding, |
16682 const std::string& location, | |
16683 bool should_match) { | 16682 bool should_match) { |
16684 HttpRequestInfo request; | 16683 HttpRequestInfo request; |
16685 request.method = "GET"; | 16684 request.method = "GET"; |
16686 request.url = GURL("http://www.foo.com/"); | 16685 request.url = GURL("http://www.foo.com/"); |
16687 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, | 16686 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
16688 accept_encoding); | 16687 accept_encoding); |
16689 | 16688 |
16690 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); | 16689 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
16691 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 16690 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
16692 // Send headers successfully, but get an error while sending the body. | 16691 // Send headers successfully, but get an error while sending the body. |
16693 MockWrite data_writes[] = { | 16692 MockWrite data_writes[] = { |
16694 MockWrite("GET / HTTP/1.1\r\n" | 16693 MockWrite("GET / HTTP/1.1\r\n" |
16695 "Host: www.foo.com\r\n" | 16694 "Host: www.foo.com\r\n" |
16696 "Connection: keep-alive\r\n" | 16695 "Connection: keep-alive\r\n" |
16697 "Accept-Encoding: "), | 16696 "Accept-Encoding: "), |
16698 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), | 16697 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
16699 }; | 16698 }; |
16700 | 16699 |
16701 std::string response_code = "200 OK"; | |
16702 std::string extra; | |
16703 if (!location.empty()) { | |
16704 response_code = "301 Redirect\r\nLocation: "; | |
16705 response_code.append(location); | |
16706 } | |
16707 | |
16708 MockRead data_reads[] = { | 16700 MockRead data_reads[] = { |
16709 MockRead("HTTP/1.0 "), | 16701 MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Encoding: "), |
16710 MockRead(response_code.data()), | 16702 MockRead(content_encoding.data()), MockRead("\r\n\r\n"), |
16711 MockRead("\r\nContent-Encoding: "), | |
16712 MockRead(content_encoding.data()), | |
16713 MockRead("\r\n\r\n"), | |
16714 MockRead(SYNCHRONOUS, OK), | 16703 MockRead(SYNCHRONOUS, OK), |
16715 }; | 16704 }; |
16716 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | 16705 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
16717 arraysize(data_writes)); | 16706 arraysize(data_writes)); |
16718 session_deps->socket_factory->AddSocketDataProvider(&data); | 16707 session_deps->socket_factory->AddSocketDataProvider(&data); |
16719 | 16708 |
16720 TestCompletionCallback callback; | 16709 TestCompletionCallback callback; |
16721 | 16710 |
16722 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); | 16711 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
16723 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 16712 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
16724 | 16713 |
16725 rv = callback.WaitForResult(); | 16714 rv = callback.WaitForResult(); |
16726 if (should_match) { | 16715 if (should_match) { |
16727 EXPECT_THAT(rv, IsOk()); | 16716 EXPECT_THAT(rv, IsOk()); |
16728 } else { | 16717 } else { |
16729 EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); | 16718 EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
16730 } | 16719 } |
16731 } | 16720 } |
16732 | 16721 |
16733 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { | 16722 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
16734 CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); | 16723 CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", false); |
16735 } | 16724 } |
16736 | 16725 |
16737 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { | 16726 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
16738 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", | 16727 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", true); |
16739 true); | |
16740 } | 16728 } |
16741 | 16729 |
16742 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { | 16730 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
16743 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | 16731 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
16744 "", false); | 16732 false); |
16745 } | |
16746 | |
16747 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { | |
16748 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", | |
16749 "www.foo.com/other", true); | |
16750 } | 16733 } |
16751 | 16734 |
16752 } // namespace net | 16735 } // namespace net |
OLD | NEW |