Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 2835403003: Do not abort redirect responses with unadvertised encoding. (Closed)
Patch Set: Pulled the check out of the loop and report "false" for valid responses Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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,
16682 bool should_match) { 16683 bool should_match) {
16683 HttpRequestInfo request; 16684 HttpRequestInfo request;
16684 request.method = "GET"; 16685 request.method = "GET";
16685 request.url = GURL("http://www.foo.com/"); 16686 request.url = GURL("http://www.foo.com/");
16686 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, 16687 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding,
16687 accept_encoding); 16688 accept_encoding);
16688 16689
16689 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); 16690 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps));
16690 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); 16691 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
16691 // Send headers successfully, but get an error while sending the body. 16692 // Send headers successfully, but get an error while sending the body.
16692 MockWrite data_writes[] = { 16693 MockWrite data_writes[] = {
16693 MockWrite("GET / HTTP/1.1\r\n" 16694 MockWrite("GET / HTTP/1.1\r\n"
16694 "Host: www.foo.com\r\n" 16695 "Host: www.foo.com\r\n"
16695 "Connection: keep-alive\r\n" 16696 "Connection: keep-alive\r\n"
16696 "Accept-Encoding: "), 16697 "Accept-Encoding: "),
16697 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), 16698 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"),
16698 }; 16699 };
16699 16700
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
16700 MockRead data_reads[] = { 16708 MockRead data_reads[] = {
16701 MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Encoding: "), 16709 MockRead("HTTP/1.0 "),
16702 MockRead(content_encoding.data()), MockRead("\r\n\r\n"), 16710 MockRead(response_code.data()),
16711 MockRead("\r\nContent-Encoding: "),
16712 MockRead(content_encoding.data()),
16713 MockRead("\r\n\r\n"),
16703 MockRead(SYNCHRONOUS, OK), 16714 MockRead(SYNCHRONOUS, OK),
16704 }; 16715 };
16705 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, 16716 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes,
16706 arraysize(data_writes)); 16717 arraysize(data_writes));
16707 session_deps->socket_factory->AddSocketDataProvider(&data); 16718 session_deps->socket_factory->AddSocketDataProvider(&data);
16708 16719
16709 TestCompletionCallback callback; 16720 TestCompletionCallback callback;
16710 16721
16711 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); 16722 int rv = trans.Start(&request, callback.callback(), NetLogWithSource());
16712 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); 16723 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
16713 16724
16714 rv = callback.WaitForResult(); 16725 rv = callback.WaitForResult();
16715 if (should_match) { 16726 if (should_match) {
16716 EXPECT_THAT(rv, IsOk()); 16727 EXPECT_THAT(rv, IsOk());
16717 } else { 16728 } else {
16718 EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); 16729 EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED));
16719 } 16730 }
16720 } 16731 }
16721 16732
16722 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { 16733 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) {
16723 CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", false); 16734 CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false);
16724 } 16735 }
16725 16736
16726 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { 16737 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) {
16727 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", true); 16738 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "",
16739 true);
16728 } 16740 }
16729 16741
16730 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { 16742 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) {
16731 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", 16743 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16732 false); 16744 "", false);
16745 }
16746
16747 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) {
16748 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip",
16749 "www.foo.com/other", true);
16733 } 16750 }
16734 16751
16735 } // namespace net 16752 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698