| 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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "net/base/address_list.h" | 14 #include "net/base/address_list.h" |
| 13 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 14 #include "net/base/winsock_init.h" | 16 #include "net/base/winsock_init.h" |
| 15 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
| 16 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, | 333 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, |
| 332 const char* status) { | 334 const char* status) { |
| 333 (*block)[spdy_util_.GetStatusKey()] = status; | 335 (*block)[spdy_util_.GetStatusKey()] = status; |
| 334 spdy_util_.MaybeAddVersionHeader(block); | 336 spdy_util_.MaybeAddVersionHeader(block); |
| 335 } | 337 } |
| 336 | 338 |
| 337 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 339 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
| 338 SpdySerializedFrame* SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { | 340 SpdySerializedFrame* SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { |
| 339 SpdyHeaderBlock block; | 341 SpdyHeaderBlock block; |
| 340 PopulateConnectRequestIR(&block); | 342 PopulateConnectRequestIR(&block); |
| 341 return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false); | 343 return spdy_util_.ConstructSpdySyn(kStreamId, std::move(block), LOWEST, |
| 344 false); |
| 342 } | 345 } |
| 343 | 346 |
| 344 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes | 347 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes |
| 345 // Proxy-Authorization headers. | 348 // Proxy-Authorization headers. |
| 346 SpdySerializedFrame* | 349 SpdySerializedFrame* |
| 347 SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { | 350 SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { |
| 348 SpdyHeaderBlock block; | 351 SpdyHeaderBlock block; |
| 349 PopulateConnectRequestIR(&block); | 352 PopulateConnectRequestIR(&block); |
| 350 block["proxy-authorization"] = "Basic Zm9vOmJhcg=="; | 353 block["proxy-authorization"] = "Basic Zm9vOmJhcg=="; |
| 351 return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false); | 354 return spdy_util_.ConstructSpdySyn(kStreamId, std::move(block), LOWEST, |
| 355 false); |
| 352 } | 356 } |
| 353 | 357 |
| 354 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. | 358 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
| 355 SpdySerializedFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { | 359 SpdySerializedFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { |
| 356 SpdyHeaderBlock block; | 360 SpdyHeaderBlock block; |
| 357 PopulateConnectReplyIR(&block, "200"); | 361 PopulateConnectReplyIR(&block, "200"); |
| 358 SpdySynReplyIR reply_ir(kStreamId); | 362 return spdy_util_.ConstructSpdyReply(kStreamId, std::move(block)); |
| 359 return spdy_util_.ConstructSpdyReply(kStreamId, block); | |
| 360 } | 363 } |
| 361 | 364 |
| 362 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, | 365 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, |
| 363 // including Proxy-Authenticate headers. | 366 // including Proxy-Authenticate headers. |
| 364 SpdySerializedFrame* | 367 SpdySerializedFrame* |
| 365 SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { | 368 SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { |
| 366 SpdyHeaderBlock block; | 369 SpdyHeaderBlock block; |
| 367 PopulateConnectReplyIR(&block, "407"); | 370 PopulateConnectReplyIR(&block, "407"); |
| 368 block["proxy-authenticate"] = "Basic realm=\"MyRealm1\""; | 371 block["proxy-authenticate"] = "Basic realm=\"MyRealm1\""; |
| 369 return spdy_util_.ConstructSpdyReply(kStreamId, block); | 372 return spdy_util_.ConstructSpdyReply(kStreamId, std::move(block)); |
| 370 } | 373 } |
| 371 | 374 |
| 372 // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. | 375 // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. |
| 373 SpdySerializedFrame* | 376 SpdySerializedFrame* |
| 374 SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { | 377 SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { |
| 375 SpdyHeaderBlock block; | 378 SpdyHeaderBlock block; |
| 376 PopulateConnectReplyIR(&block, "302"); | 379 PopulateConnectReplyIR(&block, "302"); |
| 377 block["location"] = kRedirectUrl; | 380 block["location"] = kRedirectUrl; |
| 378 block["set-cookie"] = "foo=bar"; | 381 block["set-cookie"] = "foo=bar"; |
| 379 return spdy_util_.ConstructSpdyReply(kStreamId, block); | 382 return spdy_util_.ConstructSpdyReply(kStreamId, std::move(block)); |
| 380 } | 383 } |
| 381 | 384 |
| 382 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. | 385 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. |
| 383 SpdySerializedFrame* | 386 SpdySerializedFrame* |
| 384 SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { | 387 SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { |
| 385 SpdyHeaderBlock block; | 388 SpdyHeaderBlock block; |
| 386 PopulateConnectReplyIR(&block, "500"); | 389 PopulateConnectReplyIR(&block, "500"); |
| 387 return spdy_util_.ConstructSpdyReply(kStreamId, block); | 390 return spdy_util_.ConstructSpdyReply(kStreamId, std::move(block)); |
| 388 } | 391 } |
| 389 | 392 |
| 390 SpdySerializedFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( | 393 SpdySerializedFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( |
| 391 const char* data, | 394 const char* data, |
| 392 int length) { | 395 int length) { |
| 393 return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); | 396 return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); |
| 394 } | 397 } |
| 395 | 398 |
| 396 // ----------- Connect | 399 // ----------- Connect |
| 397 | 400 |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 | 1387 |
| 1385 EXPECT_FALSE(sock_.get()); | 1388 EXPECT_FALSE(sock_.get()); |
| 1386 EXPECT_TRUE(read_callback.have_result()); | 1389 EXPECT_TRUE(read_callback.have_result()); |
| 1387 EXPECT_FALSE(write_callback_.have_result()); | 1390 EXPECT_FALSE(write_callback_.have_result()); |
| 1388 | 1391 |
| 1389 // Let the RST_STREAM write while |rst| is in-scope. | 1392 // Let the RST_STREAM write while |rst| is in-scope. |
| 1390 base::RunLoop().RunUntilIdle(); | 1393 base::RunLoop().RunUntilIdle(); |
| 1391 } | 1394 } |
| 1392 | 1395 |
| 1393 } // namespace net | 1396 } // namespace net |
| OLD | NEW |