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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 : public PlatformTest, | 64 : public PlatformTest, |
65 public testing::WithParamInterface<NextProto> { | 65 public testing::WithParamInterface<NextProto> { |
66 public: | 66 public: |
67 SpdyProxyClientSocketTest(); | 67 SpdyProxyClientSocketTest(); |
68 | 68 |
69 virtual void TearDown(); | 69 virtual void TearDown(); |
70 | 70 |
71 protected: | 71 protected: |
72 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, | 72 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes, |
73 size_t writes_count); | 73 size_t writes_count); |
74 void PopulateConnectRequestIR(SpdySynStreamIR* syn_ir); | 74 void PopulateConnectRequestIR(SpdyHeaderBlock* syn_ir); |
75 void PopulateConnectReplyIR(SpdySynReplyIR* reply_ir, const char* status); | 75 void PopulateConnectReplyIR(SpdyHeaderBlock* block, const char* status); |
76 SpdyFrame* ConstructConnectRequestFrame(); | 76 SpdyFrame* ConstructConnectRequestFrame(); |
77 SpdyFrame* ConstructConnectAuthRequestFrame(); | 77 SpdyFrame* ConstructConnectAuthRequestFrame(); |
78 SpdyFrame* ConstructConnectReplyFrame(); | 78 SpdyFrame* ConstructConnectReplyFrame(); |
79 SpdyFrame* ConstructConnectAuthReplyFrame(); | 79 SpdyFrame* ConstructConnectAuthReplyFrame(); |
80 SpdyFrame* ConstructConnectRedirectReplyFrame(); | 80 SpdyFrame* ConstructConnectRedirectReplyFrame(); |
81 SpdyFrame* ConstructConnectErrorReplyFrame(); | 81 SpdyFrame* ConstructConnectErrorReplyFrame(); |
82 SpdyFrame* ConstructBodyFrame(const char* data, int length); | 82 SpdyFrame* ConstructBodyFrame(const char* data, int length); |
83 scoped_refptr<IOBufferWithSize> CreateBuffer(const char* data, int size); | 83 scoped_refptr<IOBufferWithSize> CreateBuffer(const char* data, int size); |
84 void AssertConnectSucceeds(); | 84 void AssertConnectSucceeds(); |
85 void AssertConnectFails(int result); | 85 void AssertConnectFails(int result); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 for (int i = 0; i < num_reads; i++) { | 305 for (int i = 0; i < num_reads; i++) { |
306 Run(1); | 306 Run(1); |
307 AssertSyncReadEquals(kMsg2, kLen2); | 307 AssertSyncReadEquals(kMsg2, kLen2); |
308 } | 308 } |
309 | 309 |
310 write_callback_.WaitForResult(); | 310 write_callback_.WaitForResult(); |
311 } | 311 } |
312 | 312 |
313 void SpdyProxyClientSocketTest::PopulateConnectRequestIR( | 313 void SpdyProxyClientSocketTest::PopulateConnectRequestIR( |
314 SpdySynStreamIR* syn_ir) { | 314 SpdyHeaderBlock* block) { |
315 spdy_util_.SetPriority(LOWEST, syn_ir); | 315 (*block)[spdy_util_.GetMethodKey()] = "CONNECT"; |
316 syn_ir->SetHeader(spdy_util_.GetMethodKey(), "CONNECT"); | 316 (*block)[spdy_util_.GetPathKey()] = kOriginHostPort; |
317 syn_ir->SetHeader(spdy_util_.GetPathKey(), kOriginHostPort); | 317 (*block)[spdy_util_.GetHostKey()] = kOriginHost; |
318 syn_ir->SetHeader(spdy_util_.GetHostKey(), kOriginHost); | 318 (*block)["user-agent"] = kUserAgent; |
319 syn_ir->SetHeader("user-agent", kUserAgent); | 319 spdy_util_.MaybeAddVersionHeader(block); |
320 spdy_util_.MaybeAddVersionHeader(syn_ir); | |
321 } | 320 } |
322 | 321 |
323 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdySynReplyIR* reply_ir, | 322 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, |
324 const char* status) { | 323 const char* status) { |
325 reply_ir->SetHeader(spdy_util_.GetStatusKey(), status); | 324 (*block)[spdy_util_.GetStatusKey()] = status; |
326 spdy_util_.MaybeAddVersionHeader(reply_ir); | 325 spdy_util_.MaybeAddVersionHeader(block); |
327 } | 326 } |
328 | 327 |
329 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 328 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
330 SpdyFrame* | 329 SpdyFrame* |
331 SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { | 330 SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { |
332 SpdySynStreamIR syn_ir(kStreamId); | 331 SpdyHeaderBlock block; |
333 PopulateConnectRequestIR(&syn_ir); | 332 PopulateConnectRequestIR(&block); |
334 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); | 333 return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false, false); |
335 } | 334 } |
336 | 335 |
337 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes | 336 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes |
338 // Proxy-Authorization headers. | 337 // Proxy-Authorization headers. |
339 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { | 338 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { |
340 SpdySynStreamIR syn_ir(kStreamId); | 339 SpdyHeaderBlock block; |
341 PopulateConnectRequestIR(&syn_ir); | 340 PopulateConnectRequestIR(&block); |
342 syn_ir.SetHeader("proxy-authorization", "Basic Zm9vOmJhcg=="); | 341 block["proxy-authorization"] = "Basic Zm9vOmJhcg=="; |
343 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); | 342 return spdy_util_.ConstructSpdySyn(kStreamId, block, LOWEST, false, false); |
344 } | 343 } |
345 | 344 |
346 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. | 345 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
347 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { | 346 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { |
| 347 SpdyHeaderBlock block; |
| 348 PopulateConnectReplyIR(&block, "200"); |
348 SpdySynReplyIR reply_ir(kStreamId); | 349 SpdySynReplyIR reply_ir(kStreamId); |
349 PopulateConnectReplyIR(&reply_ir, "200"); | 350 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
350 return spdy_util_.CreateFramer(false)->SerializeFrame(reply_ir); | |
351 } | 351 } |
352 | 352 |
353 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, | 353 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, |
354 // including Proxy-Authenticate headers. | 354 // including Proxy-Authenticate headers. |
355 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { | 355 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { |
356 SpdySynReplyIR reply_ir(kStreamId); | 356 SpdyHeaderBlock block; |
357 PopulateConnectReplyIR(&reply_ir, "407"); | 357 PopulateConnectReplyIR(&block, "407"); |
358 reply_ir.SetHeader("proxy-authenticate", "Basic realm=\"MyRealm1\""); | 358 block["proxy-authenticate"] = "Basic realm=\"MyRealm1\""; |
359 return framer_.SerializeFrame(reply_ir); | 359 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
360 } | 360 } |
361 | 361 |
362 // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. | 362 // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. |
363 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { | 363 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { |
364 SpdySynReplyIR reply_ir(kStreamId); | 364 SpdyHeaderBlock block; |
365 PopulateConnectReplyIR(&reply_ir, "302"); | 365 PopulateConnectReplyIR(&block, "302"); |
366 reply_ir.SetHeader("location", kRedirectUrl); | 366 block["location"] = kRedirectUrl; |
367 reply_ir.SetHeader("set-cookie", "foo=bar"); | 367 block["set-cookie"] = "foo=bar"; |
368 return framer_.SerializeFrame(reply_ir); | 368 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
369 } | 369 } |
370 | 370 |
371 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. | 371 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. |
372 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { | 372 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { |
373 SpdySynReplyIR reply_ir(kStreamId); | 373 SpdyHeaderBlock block; |
374 PopulateConnectReplyIR(&reply_ir, "500"); | 374 PopulateConnectReplyIR(&block, "500"); |
375 return framer_.SerializeFrame(reply_ir); | 375 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
376 } | 376 } |
377 | 377 |
378 SpdyFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( | 378 SpdyFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( |
379 const char* data, | 379 const char* data, |
380 int length) { | 380 int length) { |
381 return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); | 381 return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); |
382 } | 382 } |
383 | 383 |
384 // ----------- Connect | 384 // ----------- Connect |
385 | 385 |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 | 1375 |
1376 EXPECT_FALSE(sock_.get()); | 1376 EXPECT_FALSE(sock_.get()); |
1377 EXPECT_TRUE(read_callback.have_result()); | 1377 EXPECT_TRUE(read_callback.have_result()); |
1378 EXPECT_FALSE(write_callback_.have_result()); | 1378 EXPECT_FALSE(write_callback_.have_result()); |
1379 | 1379 |
1380 // Let the RST_STREAM write while |rst| is in-scope. | 1380 // Let the RST_STREAM write while |rst| is in-scope. |
1381 base::MessageLoop::current()->RunUntilIdle(); | 1381 base::MessageLoop::current()->RunUntilIdle(); |
1382 } | 1382 } |
1383 | 1383 |
1384 } // namespace net | 1384 } // namespace net |
OLD | NEW |