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 16507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16518 trans.Start(&request, callback.callback(), NetLogWithSource())); | 16518 trans.Start(&request, callback.callback(), NetLogWithSource())); |
16519 base::RunLoop().RunUntilIdle(); | 16519 base::RunLoop().RunUntilIdle(); |
16520 | 16520 |
16521 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); | 16521 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
16522 HttpRequestHeaders headers; | 16522 HttpRequestHeaders headers; |
16523 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); | 16523 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
16524 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); | 16524 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
16525 } | 16525 } |
16526 #endif // !defined(OS_IOS) | 16526 #endif // !defined(OS_IOS) |
16527 | 16527 |
16528 void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, | |
16529 const std::string& accept_encoding, | |
16530 const std::string& content_encoding, | |
16531 bool should_match) { | |
16532 HttpRequestInfo request; | |
16533 request.method = "GET"; | |
16534 request.url = GURL("http://www.foo.com/"); | |
16535 request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, | |
16536 accept_encoding); | |
16537 | |
16538 std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); | |
16539 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | |
16540 // Send headers successfully, but get an error while sending the body. | |
16541 MockWrite data_writes[] = { | |
16542 MockWrite("GET / HTTP/1.1\r\n" | |
16543 "Host: www.foo.com\r\n" | |
16544 "Connection: keep-alive\r\n" | |
16545 "Accept-Encoding: "), | |
16546 MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), | |
16547 }; | |
16548 | |
16549 MockRead data_reads[] = { | |
16550 MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Content-Encoding: "), | |
16551 MockRead(content_encoding.data()), MockRead("\r\n\r\n"), | |
16552 MockRead(SYNCHRONOUS, OK), | |
16553 }; | |
16554 StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, | |
16555 arraysize(data_writes)); | |
16556 session_deps->socket_factory->AddSocketDataProvider(&data); | |
16557 | |
16558 TestCompletionCallback callback; | |
16559 | |
16560 int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); | |
16561 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | |
16562 | |
16563 rv = callback.WaitForResult(); | |
16564 if (should_match) { | |
16565 EXPECT_THAT(rv, IsOk()); | |
16566 } else { | |
16567 EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); | |
16568 } | |
16569 } | |
16570 | |
16571 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { | |
16572 CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", false); | |
16573 } | |
16574 | |
16575 TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { | |
16576 CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", true); | |
Randy Smith (Not in Mondays)
2017/03/28 19:55:36
Another that that confirms that we bounce gzip if
eustas
2017/04/04 10:34:30
Done.
| |
16577 } | |
16578 | |
16528 } // namespace net | 16579 } // namespace net |
OLD | NEW |