| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 9475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9486 if (rv == ERR_IO_PENDING) | 9486 if (rv == ERR_IO_PENDING) |
| 9487 rv = callback.WaitForResult(); | 9487 rv = callback.WaitForResult(); |
| 9488 EXPECT_EQ(3, rv); | 9488 EXPECT_EQ(3, rv); |
| 9489 rv = trans_compete->Read(io_buf, io_buf->size(), callback.callback()); | 9489 rv = trans_compete->Read(io_buf, io_buf->size(), callback.callback()); |
| 9490 EXPECT_EQ(0, rv); | 9490 EXPECT_EQ(0, rv); |
| 9491 | 9491 |
| 9492 // Finally, the socket is released to the group. | 9492 // Finally, the socket is released to the group. |
| 9493 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); | 9493 EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
| 9494 } | 9494 } |
| 9495 | 9495 |
| 9496 class TLSDecompressionFailureSocketDataProvider : public SocketDataProvider { | |
| 9497 public: | |
| 9498 explicit TLSDecompressionFailureSocketDataProvider(bool fail_all) | |
| 9499 : fail_all_(fail_all) { | |
| 9500 } | |
| 9501 | |
| 9502 virtual MockRead GetNextRead() OVERRIDE { | |
| 9503 if (fail_all_) | |
| 9504 return MockRead(SYNCHRONOUS, ERR_SSL_DECOMPRESSION_FAILURE_ALERT); | |
| 9505 | |
| 9506 return MockRead(SYNCHRONOUS, | |
| 9507 "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nok.\r\n"); | |
| 9508 } | |
| 9509 | |
| 9510 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE { | |
| 9511 return MockWriteResult(SYNCHRONOUS /* async */, data.size()); | |
| 9512 } | |
| 9513 | |
| 9514 virtual void Reset() OVERRIDE { | |
| 9515 } | |
| 9516 | |
| 9517 private: | |
| 9518 const bool fail_all_; | |
| 9519 }; | |
| 9520 | |
| 9521 // Test that we restart a connection when we see a decompression failure from | |
| 9522 // the peer during the handshake. (In the real world we'll restart with SSLv3 | |
| 9523 // and we won't offer DEFLATE in that case.) | |
| 9524 TEST_F(HttpNetworkTransactionSpdy2Test, RestartAfterTLSDecompressionFailure) { | |
| 9525 HttpRequestInfo request; | |
| 9526 request.method = "GET"; | |
| 9527 request.url = GURL("https://tlsdecompressionfailure.example.com/"); | |
| 9528 request.load_flags = 0; | |
| 9529 | |
| 9530 SpdySessionDependencies session_deps; | |
| 9531 TLSDecompressionFailureSocketDataProvider socket_data_provider1( | |
| 9532 false /* fail all reads */); | |
| 9533 TLSDecompressionFailureSocketDataProvider socket_data_provider2(false); | |
| 9534 SSLSocketDataProvider ssl_socket_data_provider1( | |
| 9535 SYNCHRONOUS, ERR_SSL_DECOMPRESSION_FAILURE_ALERT); | |
| 9536 SSLSocketDataProvider ssl_socket_data_provider2(SYNCHRONOUS, OK); | |
| 9537 session_deps.socket_factory->AddSocketDataProvider(&socket_data_provider1); | |
| 9538 session_deps.socket_factory->AddSocketDataProvider(&socket_data_provider2); | |
| 9539 session_deps.socket_factory->AddSSLSocketDataProvider( | |
| 9540 &ssl_socket_data_provider1); | |
| 9541 session_deps.socket_factory->AddSSLSocketDataProvider( | |
| 9542 &ssl_socket_data_provider2); | |
| 9543 | |
| 9544 // Work around http://crbug.com/37454 | |
| 9545 StaticSocketDataProvider bug37454_connection; | |
| 9546 bug37454_connection.set_connect_data(MockConnect(ASYNC, ERR_UNEXPECTED)); | |
| 9547 session_deps.socket_factory->AddSocketDataProvider(&bug37454_connection); | |
| 9548 | |
| 9549 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 9550 scoped_ptr<HttpTransaction> trans( | |
| 9551 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); | |
| 9552 TestCompletionCallback callback; | |
| 9553 | |
| 9554 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
| 9555 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 9556 EXPECT_EQ(OK, callback.WaitForResult()); | |
| 9557 | |
| 9558 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 9559 ASSERT_TRUE(response != NULL); | |
| 9560 ASSERT_TRUE(response->headers != NULL); | |
| 9561 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 9562 | |
| 9563 std::string response_data; | |
| 9564 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
| 9565 EXPECT_EQ("ok.", response_data); | |
| 9566 } | |
| 9567 | |
| 9568 // Test that we restart a connection if we get a decompression failure from the | |
| 9569 // peer while reading the first bytes from the connection. This occurs when the | |
| 9570 // peer cannot handle DEFLATE but we're using False Start, so we don't notice | |
| 9571 // in the handshake. | |
| 9572 TEST_F(HttpNetworkTransactionSpdy2Test, | |
| 9573 RestartAfterTLSDecompressionFailureWithFalseStart) { | |
| 9574 HttpRequestInfo request; | |
| 9575 request.method = "GET"; | |
| 9576 request.url = GURL("https://tlsdecompressionfailure2.example.com/"); | |
| 9577 request.load_flags = 0; | |
| 9578 | |
| 9579 SpdySessionDependencies session_deps; | |
| 9580 TLSDecompressionFailureSocketDataProvider socket_data_provider1( | |
| 9581 true /* fail all reads */); | |
| 9582 TLSDecompressionFailureSocketDataProvider socket_data_provider2(false); | |
| 9583 SSLSocketDataProvider ssl_socket_data_provider1(SYNCHRONOUS, OK); | |
| 9584 SSLSocketDataProvider ssl_socket_data_provider2(SYNCHRONOUS, OK); | |
| 9585 session_deps.socket_factory->AddSocketDataProvider(&socket_data_provider1); | |
| 9586 session_deps.socket_factory->AddSocketDataProvider(&socket_data_provider2); | |
| 9587 session_deps.socket_factory->AddSSLSocketDataProvider( | |
| 9588 &ssl_socket_data_provider1); | |
| 9589 session_deps.socket_factory->AddSSLSocketDataProvider( | |
| 9590 &ssl_socket_data_provider2); | |
| 9591 | |
| 9592 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
| 9593 scoped_ptr<HttpTransaction> trans( | |
| 9594 new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); | |
| 9595 TestCompletionCallback callback; | |
| 9596 | |
| 9597 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | |
| 9598 EXPECT_EQ(ERR_IO_PENDING, rv); | |
| 9599 EXPECT_EQ(OK, callback.WaitForResult()); | |
| 9600 | |
| 9601 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 9602 ASSERT_TRUE(response != NULL); | |
| 9603 ASSERT_TRUE(response->headers != NULL); | |
| 9604 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 9605 | |
| 9606 std::string response_data; | |
| 9607 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
| 9608 EXPECT_EQ("ok.", response_data); | |
| 9609 } | |
| 9610 | |
| 9611 // This tests the case that a request is issued via http instead of spdy after | 9496 // This tests the case that a request is issued via http instead of spdy after |
| 9612 // npn is negotiated. | 9497 // npn is negotiated. |
| 9613 TEST_F(HttpNetworkTransactionSpdy2Test, NpnWithHttpOverSSL) { | 9498 TEST_F(HttpNetworkTransactionSpdy2Test, NpnWithHttpOverSSL) { |
| 9614 HttpStreamFactory::set_use_alternate_protocols(true); | 9499 HttpStreamFactory::set_use_alternate_protocols(true); |
| 9615 HttpStreamFactory::SetNextProtos( | 9500 HttpStreamFactory::SetNextProtos( |
| 9616 MakeNextProtos("http/1.1", "http1.1", NULL)); | 9501 MakeNextProtos("http/1.1", "http1.1", NULL)); |
| 9617 SpdySessionDependencies session_deps; | 9502 SpdySessionDependencies session_deps; |
| 9618 HttpRequestInfo request; | 9503 HttpRequestInfo request; |
| 9619 request.method = "GET"; | 9504 request.method = "GET"; |
| 9620 request.url = GURL("https://www.google.com/"); | 9505 request.url = GURL("https://www.google.com/"); |
| (...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11368 trans2.Start(&request2, callback2.callback(), BoundNetLog())); | 11253 trans2.Start(&request2, callback2.callback(), BoundNetLog())); |
| 11369 MessageLoop::current()->RunUntilIdle(); | 11254 MessageLoop::current()->RunUntilIdle(); |
| 11370 data2->RunFor(3); | 11255 data2->RunFor(3); |
| 11371 | 11256 |
| 11372 ASSERT_TRUE(callback2.have_result()); | 11257 ASSERT_TRUE(callback2.have_result()); |
| 11373 EXPECT_EQ(OK, callback2.WaitForResult()); | 11258 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 11374 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); | 11259 EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 11375 } | 11260 } |
| 11376 | 11261 |
| 11377 } // namespace net | 11262 } // namespace net |
| OLD | NEW |