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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 /*require_confirmation=*/false, kQuicYieldAfterPacketsRead, | 301 /*require_confirmation=*/false, kQuicYieldAfterPacketsRead, |
318 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), | 302 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), |
319 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, | 303 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, |
320 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, | 304 "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, nullptr, |
321 base::ThreadTaskRunnerHandle::Get().get(), | 305 base::ThreadTaskRunnerHandle::Get().get(), |
322 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); | 306 /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); |
323 session_->Initialize(); | 307 session_->Initialize(); |
324 TestCompletionCallback callback; | 308 TestCompletionCallback callback; |
325 | 309 |
326 session_->CryptoConnect(callback.callback()); | 310 session_->CryptoConnect(callback.callback()); |
327 stream_.reset(use_closing_stream_ | 311 stream_.reset(new QuicHttpStream(session_->CreateHandle())); |
328 ? new AutoClosingStream(session_->CreateHandle()) | 312 promised_stream_.reset(new QuicHttpStream(session_->CreateHandle())); |
329 : new QuicHttpStream(session_->CreateHandle())); | |
330 | |
331 promised_stream_.reset(use_closing_stream_ | |
332 ? new AutoClosingStream(session_->CreateHandle()) | |
333 : new QuicHttpStream(session_->CreateHandle())); | |
334 | 313 |
335 push_promise_[":path"] = "/bar"; | 314 push_promise_[":path"] = "/bar"; |
336 push_promise_[":authority"] = "www.example.org"; | 315 push_promise_[":authority"] = "www.example.org"; |
337 push_promise_[":version"] = "HTTP/1.1"; | 316 push_promise_[":version"] = "HTTP/1.1"; |
338 push_promise_[":method"] = "GET"; | 317 push_promise_[":method"] = "GET"; |
339 push_promise_[":scheme"] = "https"; | 318 push_promise_[":scheme"] = "https"; |
340 | 319 |
341 promised_response_[":status"] = "200 OK"; | 320 promised_response_[":status"] = "200 OK"; |
342 promised_response_[":version"] = "HTTP/1.1"; | 321 promised_response_[":version"] = "HTTP/1.1"; |
343 promised_response_["content-type"] = "text/plain"; | 322 promised_response_["content-type"] = "text/plain"; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 527 |
549 QuicStreamId GetNthClientInitiatedStreamId(int n) { | 528 QuicStreamId GetNthClientInitiatedStreamId(int n) { |
550 return test::GetNthClientInitiatedStreamId(GetParam(), n); | 529 return test::GetNthClientInitiatedStreamId(GetParam(), n); |
551 } | 530 } |
552 | 531 |
553 QuicStreamId GetNthServerInitiatedStreamId(int n) { | 532 QuicStreamId GetNthServerInitiatedStreamId(int n) { |
554 return test::GetNthServerInitiatedStreamId(GetParam(), n); | 533 return test::GetNthServerInitiatedStreamId(GetParam(), n); |
555 } | 534 } |
556 | 535 |
557 BoundTestNetLog net_log_; | 536 BoundTestNetLog net_log_; |
558 bool use_closing_stream_; | |
559 MockSendAlgorithm* send_algorithm_; | 537 MockSendAlgorithm* send_algorithm_; |
560 scoped_refptr<TestTaskRunner> runner_; | 538 scoped_refptr<TestTaskRunner> runner_; |
561 std::unique_ptr<MockWrite[]> mock_writes_; | 539 std::unique_ptr<MockWrite[]> mock_writes_; |
562 MockClock clock_; | 540 MockClock clock_; |
563 TestQuicConnection* connection_; | 541 TestQuicConnection* connection_; |
564 std::unique_ptr<QuicChromiumConnectionHelper> helper_; | 542 std::unique_ptr<QuicChromiumConnectionHelper> helper_; |
565 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; | 543 std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; |
566 testing::StrictMock<MockQuicConnectionVisitor> visitor_; | 544 testing::StrictMock<MockQuicConnectionVisitor> visitor_; |
567 std::unique_ptr<QuicHttpStream> stream_; | 545 std::unique_ptr<QuicHttpStream> stream_; |
568 TransportSecurityState transport_security_state_; | 546 TransportSecurityState transport_security_state_; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1000 TEST_P(QuicHttpStreamTest, LogGranularQuicConnectionError) { | 978 TEST_P(QuicHttpStreamTest, LogGranularQuicConnectionError) { |
1001 SetRequest("GET", "/", DEFAULT_PRIORITY); | 979 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1002 size_t spdy_request_headers_frame_length; | 980 size_t spdy_request_headers_frame_length; |
1003 QuicStreamOffset header_stream_offset = 0; | 981 QuicStreamOffset header_stream_offset = 0; |
1004 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 982 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1005 AddWrite(InnerConstructRequestHeadersPacket( | 983 AddWrite(InnerConstructRequestHeadersPacket( |
1006 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, | 984 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, |
1007 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, | 985 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, |
1008 &header_stream_offset)); | 986 &header_stream_offset)); |
1009 AddWrite(ConstructAckAndRstStreamPacket(3)); | 987 AddWrite(ConstructAckAndRstStreamPacket(3)); |
1010 use_closing_stream_ = true; | |
1011 Initialize(); | 988 Initialize(); |
1012 | 989 |
1013 request_.method = "GET"; | 990 request_.method = "GET"; |
1014 request_.url = GURL("https://www.example.org/"); | 991 request_.url = GURL("https://www.example.org/"); |
1015 | 992 |
1016 EXPECT_EQ(OK, | 993 EXPECT_EQ(OK, |
1017 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 994 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
1018 net_log_.bound(), callback_.callback())); | 995 net_log_.bound(), callback_.callback())); |
1019 EXPECT_EQ(OK, | 996 EXPECT_EQ(OK, |
1020 stream_->SendRequest(headers_, &response_, callback_.callback())); | 997 stream_->SendRequest(headers_, &response_, callback_.callback())); |
(...skipping 20 matching lines...) Expand all Loading... |
1041 crypto_client_stream_factory_.set_handshake_mode( | 1018 crypto_client_stream_factory_.set_handshake_mode( |
1042 MockCryptoClientStream::ZERO_RTT); | 1019 MockCryptoClientStream::ZERO_RTT); |
1043 | 1020 |
1044 SetRequest("GET", "/", DEFAULT_PRIORITY); | 1021 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1045 size_t spdy_request_headers_frame_length; | 1022 size_t spdy_request_headers_frame_length; |
1046 QuicStreamOffset header_stream_offset = 0; | 1023 QuicStreamOffset header_stream_offset = 0; |
1047 AddWrite(InnerConstructRequestHeadersPacket( | 1024 AddWrite(InnerConstructRequestHeadersPacket( |
1048 1, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, | 1025 1, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, |
1049 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, | 1026 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, |
1050 &header_stream_offset)); | 1027 &header_stream_offset)); |
1051 use_closing_stream_ = true; | |
1052 Initialize(); | 1028 Initialize(); |
1053 | 1029 |
1054 request_.method = "GET"; | 1030 request_.method = "GET"; |
1055 request_.url = GURL("https://www.example.org/"); | 1031 request_.url = GURL("https://www.example.org/"); |
1056 | 1032 |
1057 EXPECT_EQ(OK, | 1033 EXPECT_EQ(OK, |
1058 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 1034 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
1059 net_log_.bound(), callback_.callback())); | 1035 net_log_.bound(), callback_.callback())); |
1060 EXPECT_EQ(OK, | 1036 EXPECT_EQ(OK, |
1061 stream_->SendRequest(headers_, &response_, callback_.callback())); | 1037 stream_->SendRequest(headers_, &response_, callback_.callback())); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 TEST_P(QuicHttpStreamTest, DestroyedEarly) { | 1364 TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
1389 SetRequest("GET", "/", DEFAULT_PRIORITY); | 1365 SetRequest("GET", "/", DEFAULT_PRIORITY); |
1390 size_t spdy_request_headers_frame_length; | 1366 size_t spdy_request_headers_frame_length; |
1391 QuicStreamOffset header_stream_offset = 0; | 1367 QuicStreamOffset header_stream_offset = 0; |
1392 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1368 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1393 AddWrite(InnerConstructRequestHeadersPacket( | 1369 AddWrite(InnerConstructRequestHeadersPacket( |
1394 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, | 1370 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, |
1395 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, | 1371 DEFAULT_PRIORITY, &spdy_request_headers_frame_length, |
1396 &header_stream_offset)); | 1372 &header_stream_offset)); |
1397 AddWrite(ConstructAckAndRstStreamPacket(3)); | 1373 AddWrite(ConstructAckAndRstStreamPacket(3)); |
1398 use_closing_stream_ = true; | |
1399 Initialize(); | 1374 Initialize(); |
1400 | 1375 |
1401 request_.method = "GET"; | 1376 request_.method = "GET"; |
1402 request_.url = GURL("https://www.example.org/"); | 1377 request_.url = GURL("https://www.example.org/"); |
1403 | 1378 |
1404 EXPECT_EQ(OK, | 1379 EXPECT_EQ(OK, |
1405 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, | 1380 stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
1406 net_log_.bound(), callback_.callback())); | 1381 net_log_.bound(), callback_.callback())); |
1407 EXPECT_EQ(OK, | 1382 EXPECT_EQ(OK, |
1408 stream_->SendRequest(headers_, &response_, callback_.callback())); | 1383 stream_->SendRequest(headers_, &response_, callback_.callback())); |
(...skipping 25 matching lines...) Expand all Loading... |
1434 } | 1409 } |
1435 | 1410 |
1436 TEST_P(QuicHttpStreamTest, Priority) { | 1411 TEST_P(QuicHttpStreamTest, Priority) { |
1437 SetRequest("GET", "/", MEDIUM); | 1412 SetRequest("GET", "/", MEDIUM); |
1438 size_t spdy_request_headers_frame_length; | 1413 size_t spdy_request_headers_frame_length; |
1439 QuicStreamOffset header_stream_offset = 0; | 1414 QuicStreamOffset header_stream_offset = 0; |
1440 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1415 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1441 AddWrite(InnerConstructRequestHeadersPacket( | 1416 AddWrite(InnerConstructRequestHeadersPacket( |
1442 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, | 1417 2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, |
1443 &spdy_request_headers_frame_length, &header_stream_offset)); | 1418 &spdy_request_headers_frame_length, &header_stream_offset)); |
1444 use_closing_stream_ = true; | |
1445 Initialize(); | 1419 Initialize(); |
1446 | 1420 |
1447 request_.method = "GET"; | 1421 request_.method = "GET"; |
1448 request_.url = GURL("https://www.example.org/"); | 1422 request_.url = GURL("https://www.example.org/"); |
1449 | 1423 |
1450 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), | 1424 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
1451 callback_.callback())); | 1425 callback_.callback())); |
1452 | 1426 |
1453 // Check that priority is highest. | 1427 // Check that priority is highest. |
1454 QuicChromiumClientStream::Handle* reliable_stream = | 1428 QuicChromiumClientStream::Handle* reliable_stream = |
(...skipping 26 matching lines...) Expand all Loading... |
1481 // headers and payload. | 1455 // headers and payload. |
1482 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 1456 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
1483 stream_->GetTotalSentBytes()); | 1457 stream_->GetTotalSentBytes()); |
1484 EXPECT_EQ(static_cast<int64_t>(response_size), | 1458 EXPECT_EQ(static_cast<int64_t>(response_size), |
1485 stream_->GetTotalReceivedBytes()); | 1459 stream_->GetTotalReceivedBytes()); |
1486 } | 1460 } |
1487 | 1461 |
1488 // Regression test for http://crbug.com/294870 | 1462 // Regression test for http://crbug.com/294870 |
1489 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { | 1463 TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { |
1490 SetRequest("GET", "/", MEDIUM); | 1464 SetRequest("GET", "/", MEDIUM); |
1491 use_closing_stream_ = true; | |
1492 QuicStreamOffset header_stream_offset = 0; | 1465 QuicStreamOffset header_stream_offset = 0; |
1493 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); | 1466 AddWrite(ConstructInitialSettingsPacket(&header_stream_offset)); |
1494 AddWrite(ConstructClientRstStreamPacket(2)); | 1467 AddWrite(ConstructClientRstStreamPacket(2)); |
1495 | 1468 |
1496 Initialize(); | 1469 Initialize(); |
1497 | 1470 |
1498 request_.method = "GET"; | 1471 request_.method = "GET"; |
1499 request_.url = GURL("https://www.example.org/"); | 1472 request_.url = GURL("https://www.example.org/"); |
1500 | 1473 |
1501 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), | 1474 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2156 EXPECT_TRUE(AtEof()); | 2129 EXPECT_TRUE(AtEof()); |
2157 | 2130 |
2158 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. | 2131 // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
2159 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), | 2132 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
2160 stream_->GetTotalSentBytes()); | 2133 stream_->GetTotalSentBytes()); |
2161 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); | 2134 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
2162 } | 2135 } |
2163 | 2136 |
2164 } // namespace test | 2137 } // namespace test |
2165 } // namespace net | 2138 } // namespace net |
OLD | NEW |