| 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/quic/chromium/quic_http_stream.h" | 5 #include "net/quic/chromium/quic_http_stream.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "net/base/chunked_upload_data_stream.h" | 17 #include "net/base/chunked_upload_data_stream.h" |
| 18 #include "net/base/elements_upload_data_stream.h" | 18 #include "net/base/elements_upload_data_stream.h" |
| 19 #include "net/base/load_timing_info.h" | 19 #include "net/base/load_timing_info.h" |
| 20 #include "net/base/load_timing_info_test_util.h" | 20 #include "net/base/load_timing_info_test_util.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/base/test_completion_callback.h" | 22 #include "net/base/test_completion_callback.h" |
| 23 #include "net/base/upload_bytes_element_reader.h" | 23 #include "net/base/upload_bytes_element_reader.h" |
| 24 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
| 25 #include "net/http/http_server_properties_impl.h" |
| 25 #include "net/http/transport_security_state.h" | 26 #include "net/http/transport_security_state.h" |
| 26 #include "net/log/net_log_event_type.h" | 27 #include "net/log/net_log_event_type.h" |
| 27 #include "net/log/test_net_log.h" | 28 #include "net/log/test_net_log.h" |
| 28 #include "net/log/test_net_log_util.h" | 29 #include "net/log/test_net_log_util.h" |
| 29 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 30 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
| 30 #include "net/quic/chromium/mock_crypto_client_stream_factory.h" | 31 #include "net/quic/chromium/mock_crypto_client_stream_factory.h" |
| 31 #include "net/quic/chromium/quic_chromium_alarm_factory.h" | 32 #include "net/quic/chromium/quic_chromium_alarm_factory.h" |
| 32 #include "net/quic/chromium/quic_chromium_connection_helper.h" | 33 #include "net/quic/chromium/quic_chromium_connection_helper.h" |
| 33 #include "net/quic/chromium/quic_chromium_packet_reader.h" | 34 #include "net/quic/chromium/quic_chromium_packet_reader.h" |
| 34 #include "net/quic/chromium/quic_chromium_packet_writer.h" | 35 #include "net/quic/chromium/quic_chromium_packet_writer.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 95 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 95 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 96 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 96 } | 97 } |
| 97 }; | 98 }; |
| 98 | 99 |
| 99 // Subclass of QuicHttpStream that closes itself when the first piece of data | 100 // Subclass of QuicHttpStream that closes itself when the first piece of data |
| 100 // is received. | 101 // is received. |
| 101 class AutoClosingStream : public QuicHttpStream { | 102 class AutoClosingStream : public QuicHttpStream { |
| 102 public: | 103 public: |
| 103 explicit AutoClosingStream( | 104 explicit AutoClosingStream( |
| 104 const base::WeakPtr<QuicChromiumClientSession>& session) | 105 const base::WeakPtr<QuicChromiumClientSession>& session, |
| 105 : QuicHttpStream(session) {} | 106 HttpServerProperties* http_server_properties) |
| 107 : QuicHttpStream(session, http_server_properties) {} |
| 106 | 108 |
| 107 void OnHeadersAvailable(const SpdyHeaderBlock& headers, | 109 void OnHeadersAvailable(const SpdyHeaderBlock& headers, |
| 108 size_t frame_len) override { | 110 size_t frame_len) override { |
| 109 Close(false); | 111 Close(false); |
| 110 } | 112 } |
| 111 | 113 |
| 112 void OnDataAvailable() override { Close(false); } | 114 void OnDataAvailable() override { Close(false); } |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 // UploadDataStream that always returns errors on data read. | 117 // UploadDataStream that always returns errors on data read. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), | 325 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), |
| 324 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, | 326 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, |
| 325 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, | 327 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, |
| 326 base::ThreadTaskRunnerHandle::Get().get(), | 328 base::ThreadTaskRunnerHandle::Get().get(), |
| 327 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); | 329 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); |
| 328 session_->Initialize(); | 330 session_->Initialize(); |
| 329 TestCompletionCallback callback; | 331 TestCompletionCallback callback; |
| 330 session_->CryptoConnect(callback.callback()); | 332 session_->CryptoConnect(callback.callback()); |
| 331 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); | 333 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); |
| 332 stream_.reset(use_closing_stream_ | 334 stream_.reset(use_closing_stream_ |
| 333 ? new AutoClosingStream(session_->GetWeakPtr()) | 335 ? new AutoClosingStream(session_->GetWeakPtr(), |
| 334 : new QuicHttpStream(session_->GetWeakPtr())); | 336 &http_server_properties_) |
| 337 : new QuicHttpStream(session_->GetWeakPtr(), |
| 338 &http_server_properties_)); |
| 335 | 339 |
| 336 promised_stream_.reset(use_closing_stream_ | 340 promised_stream_.reset(use_closing_stream_ |
| 337 ? new AutoClosingStream(session_->GetWeakPtr()) | 341 ? new AutoClosingStream(session_->GetWeakPtr(), |
| 338 : new QuicHttpStream(session_->GetWeakPtr())); | 342 &http_server_properties_) |
| 343 : new QuicHttpStream(session_->GetWeakPtr(), |
| 344 &http_server_properties_)); |
| 339 | 345 |
| 340 push_promise_[":path"] = "/bar"; | 346 push_promise_[":path"] = "/bar"; |
| 341 push_promise_[":authority"] = "www.example.org"; | 347 push_promise_[":authority"] = "www.example.org"; |
| 342 push_promise_[":version"] = "HTTP/1.1"; | 348 push_promise_[":version"] = "HTTP/1.1"; |
| 343 push_promise_[":method"] = "GET"; | 349 push_promise_[":method"] = "GET"; |
| 344 push_promise_[":scheme"] = "https"; | 350 push_promise_[":scheme"] = "https"; |
| 345 | 351 |
| 346 promised_response_[":status"] = "200 OK"; | 352 promised_response_[":status"] = "200 OK"; |
| 347 promised_response_[":version"] = "HTTP/1.1"; | 353 promised_response_[":version"] = "HTTP/1.1"; |
| 348 promised_response_["content-type"] = "text/plain"; | 354 promised_response_["content-type"] = "text/plain"; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 558 } |
| 553 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); | 559 ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
| 554 } | 560 } |
| 555 | 561 |
| 556 BoundTestNetLog net_log_; | 562 BoundTestNetLog net_log_; |
| 557 bool use_closing_stream_; | 563 bool use_closing_stream_; |
| 558 MockSendAlgorithm* send_algorithm_; | 564 MockSendAlgorithm* send_algorithm_; |
| 559 scoped_refptr<TestTaskRunner> runner_; | 565 scoped_refptr<TestTaskRunner> runner_; |
| 560 std::unique_ptr<MockWrite[]> mock_writes_; | 566 std::unique_ptr<MockWrite[]> mock_writes_; |
| 561 MockClock clock_; | 567 MockClock clock_; |
| 568 HttpServerPropertiesImpl http_server_properties_; |
| 562 TestQuicConnection* connection_; | 569 TestQuicConnection* connection_; |
| 563 std::unique_ptr<QuicChromiumConnectionHelper> helper_; | 570 std::unique_ptr<QuicChromiumConnectionHelper> helper_; |
| 564 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; | 571 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; |
| 565 testing::StrictMock<MockQuicConnectionVisitor> visitor_; | 572 testing::StrictMock<MockQuicConnectionVisitor> visitor_; |
| 566 std::unique_ptr<QuicHttpStream> stream_; | 573 std::unique_ptr<QuicHttpStream> stream_; |
| 567 TransportSecurityState transport_security_state_; | 574 TransportSecurityState transport_security_state_; |
| 568 std::unique_ptr<QuicChromiumClientSession> session_; | 575 std::unique_ptr<QuicChromiumClientSession> session_; |
| 569 QuicCryptoClientConfig crypto_config_; | 576 QuicCryptoClientConfig crypto_config_; |
| 570 TestCompletionCallback callback_; | 577 TestCompletionCallback callback_; |
| 571 HttpRequestInfo request_; | 578 HttpRequestInfo request_; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 request_.method = "GET"; | 718 request_.method = "GET"; |
| 712 request_.url = GURL("http://www.example.org/"); | 719 request_.url = GURL("http://www.example.org/"); |
| 713 // Start first request. | 720 // Start first request. |
| 714 EXPECT_EQ(OK, | 721 EXPECT_EQ(OK, |
| 715 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 722 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 716 net_log_.bound(), callback_.callback())); | 723 net_log_.bound(), callback_.callback())); |
| 717 EXPECT_EQ(OK, | 724 EXPECT_EQ(OK, |
| 718 stream_->SendRequest(headers_, &response_, callback_.callback())); | 725 stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 719 | 726 |
| 720 // Start a second request. | 727 // Start a second request. |
| 721 QuicHttpStream stream2(session_->GetWeakPtr()); | 728 QuicHttpStream stream2(session_->GetWeakPtr(), &http_server_properties_); |
| 722 TestCompletionCallback callback2; | 729 TestCompletionCallback callback2; |
| 723 EXPECT_EQ(OK, | 730 EXPECT_EQ(OK, |
| 724 stream2.InitializeStream(&request_, DEFAULT_PRIORITY, | 731 stream2.InitializeStream(&request_, DEFAULT_PRIORITY, |
| 725 net_log_.bound(), callback2.callback())); | 732 net_log_.bound(), callback2.callback())); |
| 726 EXPECT_EQ(OK, | 733 EXPECT_EQ(OK, |
| 727 stream2.SendRequest(headers_, &response_, callback2.callback())); | 734 stream2.SendRequest(headers_, &response_, callback2.callback())); |
| 728 | 735 |
| 729 // Ack both requests. | 736 // Ack both requests. |
| 730 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); | 737 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
| 731 | 738 |
| (...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2162 EXPECT_TRUE(AtEof()); | 2169 EXPECT_TRUE(AtEof()); |
| 2163 | 2170 |
| 2164 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. | 2171 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
| 2165 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 2172 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 2166 stream_->GetTotalSentBytes()); | 2173 stream_->GetTotalSentBytes()); |
| 2167 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 2174 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 2168 } | 2175 } |
| 2169 | 2176 |
| 2170 } // namespace test | 2177 } // namespace test |
| 2171 } // namespace net | 2178 } // namespace net |
| OLD | NEW |