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> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 writer, | 90 writer, |
91 true /* owns_writer */, | 91 true /* owns_writer */, |
92 Perspective::IS_CLIENT, | 92 Perspective::IS_CLIENT, |
93 versions) {} | 93 versions) {} |
94 | 94 |
95 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 95 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
96 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 96 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
97 } | 97 } |
98 }; | 98 }; |
99 | 99 |
100 // Subclass of QuicHttpStream that closes itself when the first piece of data | |
101 // is received. | |
102 class AutoClosingStream : public QuicHttpStream { | |
103 public: | |
104 explicit AutoClosingStream( | |
105 std::unique_ptr<QuicChromiumClientSession::Handle> session) | |
106 : QuicHttpStream(std::move(session)) {} | |
107 | |
108 void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, | |
109 size_t frame_len) override { | |
110 Close(false); | |
111 } | |
112 | |
113 }; | |
114 | |
115 // UploadDataStream that always returns errors on data read. | 100 // UploadDataStream that always returns errors on data read. |
116 class ReadErrorUploadDataStream : public UploadDataStream { | 101 class ReadErrorUploadDataStream : public UploadDataStream { |
117 public: | 102 public: |
118 enum class FailureMode { SYNC, ASYNC }; | 103 enum class FailureMode { SYNC, ASYNC }; |
119 | 104 |
120 explicit ReadErrorUploadDataStream(FailureMode mode) | 105 explicit ReadErrorUploadDataStream(FailureMode mode) |
121 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} | 106 : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
122 ~ReadErrorUploadDataStream() override {} | 107 ~ReadErrorUploadDataStream() override {} |
123 | 108 |
124 private: | 109 private: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 struct PacketToWrite { | 175 struct PacketToWrite { |
191 PacketToWrite(IoMode mode, QuicReceivedPacket* packet) | 176 PacketToWrite(IoMode mode, QuicReceivedPacket* packet) |
192 : mode(mode), packet(packet) {} | 177 : mode(mode), packet(packet) {} |
193 PacketToWrite(IoMode mode, int rv) : mode(mode), packet(nullptr), rv(rv) {} | 178 PacketToWrite(IoMode mode, int rv) : mode(mode), packet(nullptr), rv(rv) {} |
194 IoMode mode; | 179 IoMode mode; |
195 QuicReceivedPacket* packet; | 180 QuicReceivedPacket* packet; |
196 int rv; | 181 int rv; |
197 }; | 182 }; |
198 | 183 |
199 QuicHttpStreamTest() | 184 QuicHttpStreamTest() |
200 : use_closing_stream_(false), | 185 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()), |
201 crypto_config_(crypto_test_utils::ProofVerifierForTesting()), | |
202 read_buffer_(new IOBufferWithSize(4096)), | 186 read_buffer_(new IOBufferWithSize(4096)), |
203 promise_id_(GetNthServerInitiatedStreamId(0)), | 187 promise_id_(GetNthServerInitiatedStreamId(0)), |
204 stream_id_(GetNthClientInitiatedStreamId(0)), | 188 stream_id_(GetNthClientInitiatedStreamId(0)), |
205 connection_id_(2), | 189 connection_id_(2), |
206 client_maker_(GetParam(), | 190 client_maker_(GetParam(), |
207 connection_id_, | 191 connection_id_, |
208 &clock_, | 192 &clock_, |
209 kDefaultServerHostName, | 193 kDefaultServerHostName, |
210 Perspective::IS_CLIENT), | 194 Perspective::IS_CLIENT), |
211 server_maker_(GetParam(), | 195 server_maker_(GetParam(), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 /*require_confirmation=*/false, kQuicYieldAfterPacketsRead, | 303 /*require_confirmation=*/false, kQuicYieldAfterPacketsRead, |
320 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), | 304 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), |
321 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, | 305 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, |
322 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, | 306 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, |
323 base::ThreadTaskRunnerHandle::Get().get(), | 307 base::ThreadTaskRunnerHandle::Get().get(), |
324 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); | 308 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); |
325 session_->Initialize(); | 309 session_->Initialize(); |
326 TestCompletionCallback callback; | 310 TestCompletionCallback callback; |
327 | 311 |
328 session_->CryptoConnect(callback.callback()); | 312 session_->CryptoConnect(callback.callback()); |
329 stream_.reset(use_closing_stream_ | 313 stream_.reset(new QuicHttpStream(session_->CreateHandle())); |
330 ? new AutoClosingStream(session_->CreateHandle()) | 314 promised_stream_.reset(new QuicHttpStream(session_->CreateHandle())); |
331 : new QuicHttpStream(session_->CreateHandle())); | |
332 | |
333 promised_stream_.reset(use_closing_stream_ | |
334 ? new AutoClosingStream(session_->CreateHandle()) | |
335 : new QuicHttpStream(session_->CreateHandle())); | |
336 | 315 |
337 push_promise_[":path"] = "/bar"; | 316 push_promise_[":path"] = "/bar"; |
338 push_promise_[":authority"] = "www.example.org"; | 317 push_promise_[":authority"] = "www.example.org"; |
339 push_promise_[":version"] = "HTTP/1.1"; | 318 push_promise_[":version"] = "HTTP/1.1"; |
340 push_promise_[":method"] = "GET"; | 319 push_promise_[":method"] = "GET"; |
341 push_promise_[":scheme"] = "https"; | 320 push_promise_[":scheme"] = "https"; |
342 | 321 |
343 promised_response_[":status"] = "200 OK"; | 322 promised_response_[":status"] = "200 OK"; |
344 promised_response_[":version"] = "HTTP/1.1"; | 323 promised_response_[":version"] = "HTTP/1.1"; |
345 promised_response_["content-type"] = "text/plain"; | 324 promised_response_["content-type"] = "text/plain"; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 | 529 |
551 QuicStreamId GetNthClientInitiatedStreamId(int n) { | 530 QuicStreamId GetNthClientInitiatedStreamId(int n) { |
552 return test::GetNthClientInitiatedStreamId(GetParam(), n); | 531 return test::GetNthClientInitiatedStreamId(GetParam(), n); |
553 } | 532 } |
554 | 533 |
555 QuicStreamId GetNthServerInitiatedStreamId(int n) { | 534 QuicStreamId GetNthServerInitiatedStreamId(int n) { |
556 return test::GetNthServerInitiatedStreamId(GetParam(), n); | 535 return test::GetNthServerInitiatedStreamId(GetParam(), n); |
557 } | 536 } |
558 | 537 |
559 BoundTestNetLog net_log_; | 538 BoundTestNetLog net_log_; |
560 bool use_closing_stream_; | |
561 MockSendAlgorithm* send_algorithm_; | 539 MockSendAlgorithm* send_algorithm_; |
562 scoped_refptr<TestTaskRunner> runner_; | 540 scoped_refptr<TestTaskRunner> runner_; |
563 std::unique_ptr<MockWrite[]> mock_writes_; | 541 std::unique_ptr<MockWrite[]> mock_writes_; |
564 MockClock clock_; | 542 MockClock clock_; |
565 TestQuicConnection* connection_; | 543 TestQuicConnection* connection_; |
566 std::unique_ptr<QuicChromiumConnectionHelper> helper_; | 544 std::unique_ptr<QuicChromiumConnectionHelper> helper_; |
567 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; | 545 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; |
568 testing::StrictMock<MockQuicConnectionVisitor> visitor_; | 546 testing::StrictMock<MockQuicConnectionVisitor> visitor_; |
569 std::unique_ptr<UploadDataStream> upload_data_stream_; | 547 std::unique_ptr<UploadDataStream> upload_data_stream_; |
570 std::unique_ptr<QuicHttpStream> stream_; | 548 std::unique_ptr<QuicHttpStream> stream_; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 TEST_P(QuicHttpStreamTest, LogGranularQuicConnectionError) { | 981 TEST_P(QuicHttpStreamTest, LogGranularQuicConnectionError) { |
1004 SetRequest("GET", "/", DEFAULT_PRIORITY); | 982 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1005 size_t spdy_request_headers_frame_length; | 983 size_t spdy_request_headers_frame_length; |
1006 QuicStreamOffset header_stream_offset = 0; | 984 QuicStreamOffset header_stream_offset = 0; |
1007 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 985 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1008 AddWrite(InnerConstructRequestHeadersPacket( | 986 AddWrite(InnerConstructRequestHeadersPacket( |
1009 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, | 987 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, |
1010 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, | 988 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, |
1011 &header_stream_offset)); | 989 &header_stream_offset)); |
1012 AddWrite(ConstructAckAndRstStreamPacket(3)); | 990 AddWrite(ConstructAckAndRstStreamPacket(3)); |
1013 use_closing_stream_ = true; | |
1014 Initialize(); | 991 Initialize(); |
1015 | 992 |
1016 request_.method = "GET"; | 993 request_.method = "GET"; |
1017 request_.url = GURL("https://www.example.org/"); | 994 request_.url = GURL("https://www.example.org/"); |
1018 | 995 |
1019 EXPECT_EQ(OK, | 996 EXPECT_EQ(OK, |
1020 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 997 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
1021 net_log_.bound(), callback_.callback())); | 998 net_log_.bound(), callback_.callback())); |
1022 EXPECT_EQ(OK, | 999 EXPECT_EQ(OK, |
1023 stream_->SendRequest(headers_, &response_, callback_.callback())); | 1000 stream_->SendRequest(headers_, &response_, callback_.callback())); |
(...skipping 20 matching lines...) Expand all Loading... |
1044 crypto_client_stream_factory_.set_handshake_mode( | 1021 crypto_client_stream_factory_.set_handshake_mode( |
1045 MockCryptoClientStream::ZERO_RTT); | 1022 MockCryptoClientStream::ZERO_RTT); |
1046 | 1023 |
1047 SetRequest("GET", "/", DEFAULT_PRIORITY); | 1024 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1048 size_t spdy_request_headers_frame_length; | 1025 size_t spdy_request_headers_frame_length; |
1049 QuicStreamOffset header_stream_offset = 0; | 1026 QuicStreamOffset header_stream_offset = 0; |
1050 AddWrite(InnerConstructRequestHeadersPacket( | 1027 AddWrite(InnerConstructRequestHeadersPacket( |
1051 1, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, | 1028 1, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, |
1052 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, | 1029 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, |
1053 &header_stream_offset)); | 1030 &header_stream_offset)); |
1054 use_closing_stream_ = true; | |
1055 Initialize(); | 1031 Initialize(); |
1056 | 1032 |
1057 request_.method = "GET"; | 1033 request_.method = "GET"; |
1058 request_.url = GURL("https://www.example.org/"); | 1034 request_.url = GURL("https://www.example.org/"); |
1059 | 1035 |
1060 EXPECT_EQ(OK, | 1036 EXPECT_EQ(OK, |
1061 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 1037 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
1062 net_log_.bound(), callback_.callback())); | 1038 net_log_.bound(), callback_.callback())); |
1063 EXPECT_EQ(OK, | 1039 EXPECT_EQ(OK, |
1064 stream_->SendRequest(headers_, &response_, callback_.callback())); | 1040 stream_->SendRequest(headers_, &response_, callback_.callback())); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 1374 TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
1399 SetRequest("GET", "/", DEFAULT_PRIORITY); | 1375 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1400 size_t spdy_request_headers_frame_length; | 1376 size_t spdy_request_headers_frame_length; |
1401 QuicStreamOffset header_stream_offset = 0; | 1377 QuicStreamOffset header_stream_offset = 0; |
1402 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1378 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1403 AddWrite(InnerConstructRequestHeadersPacket( | 1379 AddWrite(InnerConstructRequestHeadersPacket( |
1404 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, | 1380 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, |
1405 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, | 1381 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, |
1406 &header_stream_offset)); | 1382 &header_stream_offset)); |
1407 AddWrite(ConstructAckAndRstStreamPacket(3)); | 1383 AddWrite(ConstructAckAndRstStreamPacket(3)); |
1408 use_closing_stream_ = true; | |
1409 Initialize(); | 1384 Initialize(); |
1410 | 1385 |
1411 request_.method = "GET"; | 1386 request_.method = "GET"; |
1412 request_.url = GURL("https://www.example.org/"); | 1387 request_.url = GURL("https://www.example.org/"); |
1413 | 1388 |
1414 EXPECT_EQ(OK, | 1389 EXPECT_EQ(OK, |
1415 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 1390 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
1416 net_log_.bound(), callback_.callback())); | 1391 net_log_.bound(), callback_.callback())); |
1417 EXPECT_EQ(OK, | 1392 EXPECT_EQ(OK, |
1418 stream_->SendRequest(headers_, &response_, callback_.callback())); | 1393 stream_->SendRequest(headers_, &response_, callback_.callback())); |
(...skipping 25 matching lines...) Expand all Loading... |
1444 } | 1419 } |
1445 | 1420 |
1446 TEST_P(QuicHttpStreamTest, Priority) { | 1421 TEST_P(QuicHttpStreamTest, Priority) { |
1447 SetRequest("GET", "/", MEDIUM); | 1422 SetRequest("GET", "/", MEDIUM); |
1448 size_t spdy_request_headers_frame_length; | 1423 size_t spdy_request_headers_frame_length; |
1449 QuicStreamOffset header_stream_offset = 0; | 1424 QuicStreamOffset header_stream_offset = 0; |
1450 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1425 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1451 AddWrite(InnerConstructRequestHeadersPacket( | 1426 AddWrite(InnerConstructRequestHeadersPacket( |
1452 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, | 1427 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, |
1453 &spdy_request_headers_frame_length, &header_stream_offset)); | 1428 &spdy_request_headers_frame_length, &header_stream_offset)); |
1454 use_closing_stream_ = true; | |
1455 Initialize(); | 1429 Initialize(); |
1456 | 1430 |
1457 request_.method = "GET"; | 1431 request_.method = "GET"; |
1458 request_.url = GURL("https://www.example.org/"); | 1432 request_.url = GURL("https://www.example.org/"); |
1459 | 1433 |
1460 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), | 1434 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
1461 callback_.callback())); | 1435 callback_.callback())); |
1462 | 1436 |
1463 // Check that priority is highest. | 1437 // Check that priority is highest. |
1464 QuicChromiumClientStream::Handle* reliable_stream = | 1438 QuicChromiumClientStream::Handle* reliable_stream = |
(...skipping 26 matching lines...) Expand all Loading... |
1491 // headers and payload. | 1465 // headers and payload. |
1492 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 1466 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
1493 stream_->GetTotalSentBytes()); | 1467 stream_->GetTotalSentBytes()); |
1494 EXPECT_EQ(static_cast<int64_t>(response_size), | 1468 EXPECT_EQ(static_cast<int64_t>(response_size), |
1495 stream_->GetTotalReceivedBytes()); | 1469 stream_->GetTotalReceivedBytes()); |
1496 } | 1470 } |
1497 | 1471 |
1498 // Regression test for http://crbug.com/294870 | 1472 // Regression test for http://crbug.com/294870 |
1499 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { | 1473 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { |
1500 SetRequest("GET", "/", MEDIUM); | 1474 SetRequest("GET", "/", MEDIUM); |
1501 use_closing_stream_ = true; | |
1502 QuicStreamOffset header_stream_offset = 0; | 1475 QuicStreamOffset header_stream_offset = 0; |
1503 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1476 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1504 AddWrite(ConstructClientRstStreamPacket(2)); | 1477 AddWrite(ConstructClientRstStreamPacket(2)); |
1505 | 1478 |
1506 Initialize(); | 1479 Initialize(); |
1507 | 1480 |
1508 request_.method = "GET"; | 1481 request_.method = "GET"; |
1509 request_.url = GURL("https://www.example.org/"); | 1482 request_.url = GURL("https://www.example.org/"); |
1510 | 1483 |
1511 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), | 1484 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2170 EXPECT_TRUE(AtEof()); | 2143 EXPECT_TRUE(AtEof()); |
2171 | 2144 |
2172 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. | 2145 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
2173 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 2146 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
2174 stream_->GetTotalSentBytes()); | 2147 stream_->GetTotalSentBytes()); |
2175 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 2148 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
2176 } | 2149 } |
2177 | 2150 |
2178 } // namespace test | 2151 } // namespace test |
2179 } // namespace net | 2152 } // namespace net |
OLD | NEW |