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 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 : QuicSimpleServerStream(id, session), response_body_(response_body) {} | 1941 : QuicSimpleServerStream(id, session), response_body_(response_body) {} |
1942 | 1942 |
1943 ~ServerStreamWithErrorResponseBody() override {} | 1943 ~ServerStreamWithErrorResponseBody() override {} |
1944 | 1944 |
1945 protected: | 1945 protected: |
1946 void SendErrorResponse() override { | 1946 void SendErrorResponse() override { |
1947 DVLOG(1) << "Sending error response for stream " << id(); | 1947 DVLOG(1) << "Sending error response for stream " << id(); |
1948 SpdyHeaderBlock headers; | 1948 SpdyHeaderBlock headers; |
1949 headers[":status"] = "500"; | 1949 headers[":status"] = "500"; |
1950 headers["content-length"] = base::UintToString(response_body_.size()); | 1950 headers["content-length"] = base::UintToString(response_body_.size()); |
| 1951 response_.set_headers(headers); |
| 1952 response_.set_body(response_body_); |
1951 // This method must call CloseReadSide to cause the test case, StopReading | 1953 // This method must call CloseReadSide to cause the test case, StopReading |
1952 // is not sufficient. | 1954 // is not sufficient. |
1953 ReliableQuicStreamPeer::CloseReadSide(this); | 1955 ReliableQuicStreamPeer::CloseReadSide(this); |
1954 SendHeadersAndBody(headers, response_body_); | 1956 next_state_ = SEND_HEADERS; |
| 1957 DoLoop(); |
1955 } | 1958 } |
1956 | 1959 |
1957 string response_body_; | 1960 string response_body_; |
1958 }; | 1961 }; |
1959 | 1962 |
1960 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { | 1963 class StreamWithErrorFactory : public QuicTestServer::StreamFactory { |
1961 public: | 1964 public: |
1962 explicit StreamWithErrorFactory(string response_body) | 1965 explicit StreamWithErrorFactory(string response_body) |
1963 : response_body_(response_body) {} | 1966 : response_body_(response_body) {} |
1964 | 1967 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2113 trailers["some-trailing-header"] = "trailing-header-value"; | 2116 trailers["some-trailing-header"] = "trailing-header-value"; |
2114 | 2117 |
2115 QuicInMemoryCache::GetInstance()->AddResponse( | 2118 QuicInMemoryCache::GetInstance()->AddResponse( |
2116 "www.google.com", "/trailer_url", headers, kBody, trailers); | 2119 "www.google.com", "/trailer_url", headers, kBody, trailers); |
2117 | 2120 |
2118 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); | 2121 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); |
2119 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 2122 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
2120 EXPECT_EQ(trailers, client_->response_trailers()); | 2123 EXPECT_EQ(trailers, client_->response_trailers()); |
2121 } | 2124 } |
2122 | 2125 |
| 2126 TEST_P(EndToEndTest, MultipartResponse) { |
| 2127 // Test QuicInMemoryCache::AddBidirectionalResponse with multipart response |
| 2128 // body works. However, this does not have full coverage since the client only |
| 2129 // supports request/response and not bidirectional streaming. |
| 2130 ASSERT_TRUE(Initialize()); |
| 2131 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 2132 |
| 2133 // Set reordering to ensure that Trailers arriving before body is ok. |
| 2134 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
| 2135 SetReorderPercentage(30); |
| 2136 |
| 2137 // Add a response with headers, body, and trailers. |
| 2138 const string kBody = "body content"; |
| 2139 |
| 2140 SpdyHeaderBlock headers; |
| 2141 headers[":status"] = "200"; |
| 2142 headers[":version"] = "HTTP/1.1"; |
| 2143 headers["content-length"] = IntToString(kBody.size()); |
| 2144 |
| 2145 SpdyHeaderBlock trailers; |
| 2146 trailers["some-trailing-header"] = "trailing-header-value"; |
| 2147 std::vector<std::string> multipart_body; |
| 2148 multipart_body.push_back("hellooo!"); |
| 2149 multipart_body.push_back("here's my second part."); |
| 2150 multipart_body.push_back("here's my third part."); |
| 2151 |
| 2152 QuicInMemoryCache::GetInstance()->AddBidirectionalResponse( |
| 2153 "www.google.com", "/trailer_url", 200, multipart_body, trailers); |
| 2154 |
| 2155 std::string expected; |
| 2156 for (auto s : multipart_body) { |
| 2157 expected.append(s); |
| 2158 } |
| 2159 EXPECT_EQ(expected, client_->SendSynchronousRequest("/trailer_url")); |
| 2160 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 2161 EXPECT_EQ(trailers, client_->response_trailers()); |
| 2162 } |
| 2163 |
2123 class EndToEndTestServerPush : public EndToEndTest { | 2164 class EndToEndTestServerPush : public EndToEndTest { |
2124 protected: | 2165 protected: |
2125 const size_t kNumMaxStreams = 10; | 2166 const size_t kNumMaxStreams = 10; |
2126 | 2167 |
2127 EndToEndTestServerPush() : EndToEndTest() { | 2168 EndToEndTestServerPush() : EndToEndTest() { |
2128 FLAGS_quic_supports_push_promise = true; | 2169 FLAGS_quic_supports_push_promise = true; |
2129 FLAGS_quic_different_max_num_open_streams = true; | 2170 FLAGS_quic_different_max_num_open_streams = true; |
2130 client_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); | 2171 client_config_.SetMaxStreamsPerConnection(kNumMaxStreams, kNumMaxStreams); |
2131 } | 2172 } |
2132 | 2173 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2366 // sending requests for them. | 2407 // sending requests for them. |
2367 EXPECT_EQ(1u, client_->num_requests()); | 2408 EXPECT_EQ(1u, client_->num_requests()); |
2368 // Including response to original request, 12 responses in total were | 2409 // Including response to original request, 12 responses in total were |
2369 // recieved. | 2410 // recieved. |
2370 EXPECT_EQ(12u, client_->num_responses()); | 2411 EXPECT_EQ(12u, client_->num_responses()); |
2371 } | 2412 } |
2372 | 2413 |
2373 } // namespace | 2414 } // namespace |
2374 } // namespace test | 2415 } // namespace test |
2375 } // namespace net | 2416 } // namespace net |
OLD | NEW |