| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <sys/epoll.h> | 6 #include <sys/epoll.h> |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <ostream> | 11 #include <ostream> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/strings/string_number_conversions.h" | |
| 19 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
| 21 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 22 #include "net/base/ip_address.h" | 21 #include "net/base/ip_address.h" |
| 23 #include "net/base/ip_endpoint.h" | 22 #include "net/base/ip_endpoint.h" |
| 24 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 23 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
| 25 #include "net/quic/core/crypto/null_encrypter.h" | 24 #include "net/quic/core/crypto/null_encrypter.h" |
| 26 #include "net/quic/core/quic_client_session_base.h" | 25 #include "net/quic/core/quic_client_session_base.h" |
| 27 #include "net/quic/core/quic_flags.h" | 26 #include "net/quic/core/quic_flags.h" |
| 28 #include "net/quic/core/quic_framer.h" | 27 #include "net/quic/core/quic_framer.h" |
| 29 #include "net/quic/core/quic_packet_creator.h" | 28 #include "net/quic/core/quic_packet_creator.h" |
| 30 #include "net/quic/core/quic_packets.h" | 29 #include "net/quic/core/quic_packets.h" |
| 31 #include "net/quic/core/quic_server_id.h" | 30 #include "net/quic/core/quic_server_id.h" |
| 32 #include "net/quic/core/quic_session.h" | 31 #include "net/quic/core/quic_session.h" |
| 33 #include "net/quic/core/quic_utils.h" | 32 #include "net/quic/core/quic_utils.h" |
| 34 #include "net/quic/platform/api/quic_socket_address.h" | 33 #include "net/quic/platform/api/quic_socket_address.h" |
| 35 #include "net/quic/platform/api/quic_str_cat.h" | 34 #include "net/quic/platform/api/quic_str_cat.h" |
| 35 #include "net/quic/platform/api/quic_text_utils.h" |
| 36 #include "net/quic/test_tools/crypto_test_utils.h" | 36 #include "net/quic/test_tools/crypto_test_utils.h" |
| 37 #include "net/quic/test_tools/quic_config_peer.h" | 37 #include "net/quic/test_tools/quic_config_peer.h" |
| 38 #include "net/quic/test_tools/quic_connection_peer.h" | 38 #include "net/quic/test_tools/quic_connection_peer.h" |
| 39 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 39 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 40 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 40 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 41 #include "net/quic/test_tools/quic_session_peer.h" | 41 #include "net/quic/test_tools/quic_session_peer.h" |
| 42 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 42 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 43 #include "net/quic/test_tools/quic_stream_peer.h" | 43 #include "net/quic/test_tools/quic_stream_peer.h" |
| 44 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 44 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
| 45 #include "net/quic/test_tools/quic_test_utils.h" | 45 #include "net/quic/test_tools/quic_test_utils.h" |
| (...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2247 : QuicSimpleServerStream(id, session, response_cache), | 2247 : QuicSimpleServerStream(id, session, response_cache), |
| 2248 response_body_(std::move(response_body)) {} | 2248 response_body_(std::move(response_body)) {} |
| 2249 | 2249 |
| 2250 ~ServerStreamWithErrorResponseBody() override {} | 2250 ~ServerStreamWithErrorResponseBody() override {} |
| 2251 | 2251 |
| 2252 protected: | 2252 protected: |
| 2253 void SendErrorResponse() override { | 2253 void SendErrorResponse() override { |
| 2254 DVLOG(1) << "Sending error response for stream " << id(); | 2254 DVLOG(1) << "Sending error response for stream " << id(); |
| 2255 SpdyHeaderBlock headers; | 2255 SpdyHeaderBlock headers; |
| 2256 headers[":status"] = "500"; | 2256 headers[":status"] = "500"; |
| 2257 headers["content-length"] = base::UintToString(response_body_.size()); | 2257 headers["content-length"] = |
| 2258 QuicTextUtils::Uint64ToString(response_body_.size()); |
| 2258 // This method must call CloseReadSide to cause the test case, StopReading | 2259 // This method must call CloseReadSide to cause the test case, StopReading |
| 2259 // is not sufficient. | 2260 // is not sufficient. |
| 2260 QuicStreamPeer::CloseReadSide(this); | 2261 QuicStreamPeer::CloseReadSide(this); |
| 2261 SendHeadersAndBody(std::move(headers), response_body_); | 2262 SendHeadersAndBody(std::move(headers), response_body_); |
| 2262 } | 2263 } |
| 2263 | 2264 |
| 2264 string response_body_; | 2265 string response_body_; |
| 2265 }; | 2266 }; |
| 2266 | 2267 |
| 2267 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { | 2268 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2580 // Set reordering to ensure that Trailers arriving before body is ok. | 2581 // Set reordering to ensure that Trailers arriving before body is ok. |
| 2581 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2582 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
| 2582 SetReorderPercentage(30); | 2583 SetReorderPercentage(30); |
| 2583 | 2584 |
| 2584 // Add a response with headers, body, and trailers. | 2585 // Add a response with headers, body, and trailers. |
| 2585 const string kBody = "body content"; | 2586 const string kBody = "body content"; |
| 2586 | 2587 |
| 2587 SpdyHeaderBlock headers; | 2588 SpdyHeaderBlock headers; |
| 2588 headers[":status"] = "200"; | 2589 headers[":status"] = "200"; |
| 2589 headers[":version"] = "HTTP/1.1"; | 2590 headers[":version"] = "HTTP/1.1"; |
| 2590 headers["content-length"] = IntToString(kBody.size()); | 2591 headers["content-length"] = QuicTextUtils::Uint64ToString(kBody.size()); |
| 2591 | 2592 |
| 2592 SpdyHeaderBlock trailers; | 2593 SpdyHeaderBlock trailers; |
| 2593 trailers["some-trailing-header"] = "trailing-header-value"; | 2594 trailers["some-trailing-header"] = "trailing-header-value"; |
| 2594 | 2595 |
| 2595 response_cache_.AddResponse(server_hostname_, "/trailer_url", | 2596 response_cache_.AddResponse(server_hostname_, "/trailer_url", |
| 2596 std::move(headers), kBody, trailers.Clone()); | 2597 std::move(headers), kBody, trailers.Clone()); |
| 2597 | 2598 |
| 2598 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); | 2599 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); |
| 2599 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); | 2600 EXPECT_EQ("200", client_->response_headers()->find(":status")->second); |
| 2600 EXPECT_EQ(trailers, client_->response_trailers()); | 2601 EXPECT_EQ(trailers, client_->response_trailers()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2634 for (size_t i = 0; i < num_resources; ++i) { | 2635 for (size_t i = 0; i < num_resources; ++i) { |
| 2635 string url = push_urls[i]; | 2636 string url = push_urls[i]; |
| 2636 GURL resource_url(url); | 2637 GURL resource_url(url); |
| 2637 string body = | 2638 string body = |
| 2638 use_large_response | 2639 use_large_response |
| 2639 ? large_resource | 2640 ? large_resource |
| 2640 : QuicStrCat("This is server push response body for ", url); | 2641 : QuicStrCat("This is server push response body for ", url); |
| 2641 SpdyHeaderBlock response_headers; | 2642 SpdyHeaderBlock response_headers; |
| 2642 response_headers[":version"] = "HTTP/1.1"; | 2643 response_headers[":version"] = "HTTP/1.1"; |
| 2643 response_headers[":status"] = "200"; | 2644 response_headers[":status"] = "200"; |
| 2644 response_headers["content-length"] = IntToString(body.size()); | 2645 response_headers["content-length"] = |
| 2646 QuicTextUtils::Uint64ToString(body.size()); |
| 2645 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( | 2647 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( |
| 2646 resource_url, std::move(response_headers), kV3LowestPriority, body)); | 2648 resource_url, std::move(response_headers), kV3LowestPriority, body)); |
| 2647 } | 2649 } |
| 2648 | 2650 |
| 2649 response_cache_.AddSimpleResponseWithServerPushResources( | 2651 response_cache_.AddSimpleResponseWithServerPushResources( |
| 2650 host, path, 200, response_body, push_resources); | 2652 host, path, 200, response_body, push_resources); |
| 2651 } | 2653 } |
| 2652 }; | 2654 }; |
| 2653 | 2655 |
| 2654 // Run all server push end to end tests with all supported versions. | 2656 // Run all server push end to end tests with all supported versions. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2936 // Request body size is 4G plus one more kSizeBytes. | 2938 // Request body size is 4G plus one more kSizeBytes. |
| 2937 int64_t request_body_size_bytes = pow(2, 32) + kSizeBytes; | 2939 int64_t request_body_size_bytes = pow(2, 32) + kSizeBytes; |
| 2938 ASSERT_LT(INT64_C(4294967296), request_body_size_bytes); | 2940 ASSERT_LT(INT64_C(4294967296), request_body_size_bytes); |
| 2939 string body(kSizeBytes, 'a'); | 2941 string body(kSizeBytes, 'a'); |
| 2940 | 2942 |
| 2941 SpdyHeaderBlock headers; | 2943 SpdyHeaderBlock headers; |
| 2942 headers[":method"] = "POST"; | 2944 headers[":method"] = "POST"; |
| 2943 headers[":path"] = "/foo"; | 2945 headers[":path"] = "/foo"; |
| 2944 headers[":scheme"] = "https"; | 2946 headers[":scheme"] = "https"; |
| 2945 headers[":authority"] = server_hostname_; | 2947 headers[":authority"] = server_hostname_; |
| 2946 headers["content-length"] = IntToString(request_body_size_bytes); | 2948 headers["content-length"] = |
| 2949 QuicTextUtils::Uint64ToString(request_body_size_bytes); |
| 2947 | 2950 |
| 2948 client_->SendMessage(headers, "", /*fin=*/false); | 2951 client_->SendMessage(headers, "", /*fin=*/false); |
| 2949 | 2952 |
| 2950 for (int i = 0; i < request_body_size_bytes / kSizeBytes; ++i) { | 2953 for (int i = 0; i < request_body_size_bytes / kSizeBytes; ++i) { |
| 2951 bool fin = (i == request_body_size_bytes - 1); | 2954 bool fin = (i == request_body_size_bytes - 1); |
| 2952 client_->SendData(string(body.data(), kSizeBytes), fin); | 2955 client_->SendData(string(body.data(), kSizeBytes), fin); |
| 2953 client_->client()->WaitForEvents(); | 2956 client_->client()->WaitForEvents(); |
| 2954 } | 2957 } |
| 2955 VerifyCleanConnection(true); | 2958 VerifyCleanConnection(true); |
| 2956 } | 2959 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3056 client_->WaitForResponse(); | 3059 client_->WaitForResponse(); |
| 3057 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 3060 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 3058 QuicConnectionStats client_stats = | 3061 QuicConnectionStats client_stats = |
| 3059 client_->client()->session()->connection()->GetStats(); | 3062 client_->client()->session()->connection()->GetStats(); |
| 3060 EXPECT_EQ(0u, client_stats.packets_lost); | 3063 EXPECT_EQ(0u, client_stats.packets_lost); |
| 3061 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 3064 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 3062 } | 3065 } |
| 3063 } // namespace | 3066 } // namespace |
| 3064 } // namespace test | 3067 } // namespace test |
| 3065 } // namespace net | 3068 } // namespace net |
| OLD | NEW |