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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(SpdySynStreamIR* 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 void SpdyProxyClientSocketTest::PopulateConnectRequestIR( | 313 void SpdyProxyClientSocketTest::PopulateConnectRequestIR( |
314 SpdySynStreamIR* syn_ir) { | 314 SpdySynStreamIR* syn_ir) { |
315 spdy_util_.SetPriority(LOWEST, syn_ir); | 315 spdy_util_.SetPriority(LOWEST, syn_ir); |
316 syn_ir->SetHeader(spdy_util_.GetMethodKey(), "CONNECT"); | 316 syn_ir->SetHeader(spdy_util_.GetMethodKey(), "CONNECT"); |
317 syn_ir->SetHeader(spdy_util_.GetPathKey(), kOriginHostPort); | 317 syn_ir->SetHeader(spdy_util_.GetPathKey(), kOriginHostPort); |
318 syn_ir->SetHeader(spdy_util_.GetHostKey(), kOriginHost); | 318 syn_ir->SetHeader(spdy_util_.GetHostKey(), kOriginHost); |
319 syn_ir->SetHeader("user-agent", kUserAgent); | 319 syn_ir->SetHeader("user-agent", kUserAgent); |
320 spdy_util_.MaybeAddVersionHeader(syn_ir); | 320 spdy_util_.MaybeAddVersionHeader(syn_ir); |
321 } | 321 } |
322 | 322 |
323 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdySynReplyIR* reply_ir, | 323 void SpdyProxyClientSocketTest::PopulateConnectReplyIR(SpdyHeaderBlock* block, |
324 const char* status) { | 324 const char* status) { |
325 reply_ir->SetHeader(spdy_util_.GetStatusKey(), status); | 325 (*block)[spdy_util_.GetStatusKey()] = status; |
326 spdy_util_.MaybeAddVersionHeader(reply_ir); | 326 spdy_util_.MaybeAddVersionHeader(block); |
327 } | 327 } |
328 | 328 |
329 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. | 329 // Constructs a standard SPDY SYN_STREAM frame for a CONNECT request. |
330 SpdyFrame* | 330 SpdyFrame* |
331 SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { | 331 SpdyProxyClientSocketTest::ConstructConnectRequestFrame() { |
332 SpdySynStreamIR syn_ir(kStreamId); | 332 SpdySynStreamIR syn_ir(kStreamId); |
333 PopulateConnectRequestIR(&syn_ir); | 333 PopulateConnectRequestIR(&syn_ir); |
334 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); | 334 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); |
335 } | 335 } |
336 | 336 |
337 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes | 337 // Constructs a SPDY SYN_STREAM frame for a CONNECT request which includes |
338 // Proxy-Authorization headers. | 338 // Proxy-Authorization headers. |
339 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { | 339 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { |
340 SpdySynStreamIR syn_ir(kStreamId); | 340 SpdySynStreamIR syn_ir(kStreamId); |
341 PopulateConnectRequestIR(&syn_ir); | 341 PopulateConnectRequestIR(&syn_ir); |
342 syn_ir.SetHeader("proxy-authorization", "Basic Zm9vOmJhcg=="); | 342 syn_ir.SetHeader("proxy-authorization", "Basic Zm9vOmJhcg=="); |
343 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); | 343 return spdy_util_.CreateFramer(false)->SerializeFrame(syn_ir); |
344 } | 344 } |
345 | 345 |
346 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. | 346 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT. |
347 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { | 347 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { |
| 348 SpdyHeaderBlock block; |
| 349 PopulateConnectReplyIR(&block, "200"); |
348 SpdySynReplyIR reply_ir(kStreamId); | 350 SpdySynReplyIR reply_ir(kStreamId); |
349 PopulateConnectReplyIR(&reply_ir, "200"); | 351 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
350 return spdy_util_.CreateFramer(false)->SerializeFrame(reply_ir); | |
351 } | 352 } |
352 | 353 |
353 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, | 354 // Constructs a standard SPDY SYN_REPLY frame to match the SPDY CONNECT, |
354 // including Proxy-Authenticate headers. | 355 // including Proxy-Authenticate headers. |
355 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { | 356 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { |
356 SpdySynReplyIR reply_ir(kStreamId); | 357 SpdyHeaderBlock block; |
357 PopulateConnectReplyIR(&reply_ir, "407"); | 358 PopulateConnectReplyIR(&block, "407"); |
358 reply_ir.SetHeader("proxy-authenticate", "Basic realm=\"MyRealm1\""); | 359 block["proxy-authenticate"] = "Basic realm=\"MyRealm1\""; |
359 return framer_.SerializeFrame(reply_ir); | 360 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
360 } | 361 } |
361 | 362 |
362 // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. | 363 // Constructs a SPDY SYN_REPLY frame with an HTTP 302 redirect. |
363 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { | 364 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { |
364 SpdySynReplyIR reply_ir(kStreamId); | 365 SpdyHeaderBlock block; |
365 PopulateConnectReplyIR(&reply_ir, "302"); | 366 PopulateConnectReplyIR(&block, "302"); |
366 reply_ir.SetHeader("location", kRedirectUrl); | 367 block["location"] = kRedirectUrl; |
367 reply_ir.SetHeader("set-cookie", "foo=bar"); | 368 block["set-cookie"] = "foo=bar"; |
368 return framer_.SerializeFrame(reply_ir); | 369 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
369 } | 370 } |
370 | 371 |
371 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. | 372 // Constructs a SPDY SYN_REPLY frame with an HTTP 500 error. |
372 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { | 373 SpdyFrame* SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { |
373 SpdySynReplyIR reply_ir(kStreamId); | 374 SpdyHeaderBlock block; |
374 PopulateConnectReplyIR(&reply_ir, "500"); | 375 PopulateConnectReplyIR(&block, "500"); |
375 return framer_.SerializeFrame(reply_ir); | 376 return spdy_util_.ConstructSpdyReply(kStreamId, block); |
376 } | 377 } |
377 | 378 |
378 SpdyFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( | 379 SpdyFrame* SpdyProxyClientSocketTest::ConstructBodyFrame( |
379 const char* data, | 380 const char* data, |
380 int length) { | 381 int length) { |
381 return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); | 382 return framer_.CreateDataFrame(kStreamId, data, length, DATA_FLAG_NONE); |
382 } | 383 } |
383 | 384 |
384 // ----------- Connect | 385 // ----------- Connect |
385 | 386 |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 | 1376 |
1376 EXPECT_FALSE(sock_.get()); | 1377 EXPECT_FALSE(sock_.get()); |
1377 EXPECT_TRUE(read_callback.have_result()); | 1378 EXPECT_TRUE(read_callback.have_result()); |
1378 EXPECT_FALSE(write_callback_.have_result()); | 1379 EXPECT_FALSE(write_callback_.have_result()); |
1379 | 1380 |
1380 // Let the RST_STREAM write while |rst| is in-scope. | 1381 // Let the RST_STREAM write while |rst| is in-scope. |
1381 base::MessageLoop::current()->RunUntilIdle(); | 1382 base::MessageLoop::current()->RunUntilIdle(); |
1382 } | 1383 } |
1383 | 1384 |
1384 } // namespace net | 1385 } // namespace net |
OLD | NEW |