| 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/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 "Host: www.google.com\r\n" | 240 "Host: www.google.com\r\n" |
| 241 "Proxy-Connection: keep-alive\r\n\r\n"), | 241 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 242 }; | 242 }; |
| 243 MockRead reads[] = { | 243 MockRead reads[] = { |
| 244 // No credentials. | 244 // No credentials. |
| 245 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), | 245 MockRead(ASYNC, 1, "HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 246 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), | 246 MockRead(ASYNC, 2, "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 247 MockRead(ASYNC, 3, "Content-Length: 10\r\n\r\n"), | 247 MockRead(ASYNC, 3, "Content-Length: 10\r\n\r\n"), |
| 248 MockRead(ASYNC, 4, "0123456789"), | 248 MockRead(ASYNC, 4, "0123456789"), |
| 249 }; | 249 }; |
| 250 scoped_ptr<SpdyFrame> req(ConstructSpdyConnect(NULL, 0, 1)); | 250 scoped_ptr<SpdyFrame> req( |
| 251 spdy_util_.ConstructSpdyConnect(NULL, 0, 1)); |
| 251 scoped_ptr<SpdyFrame> rst( | 252 scoped_ptr<SpdyFrame> rst( |
| 252 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 253 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 253 MockWrite spdy_writes[] = { | 254 MockWrite spdy_writes[] = { |
| 254 CreateMockWrite(*req, 0, ASYNC), | 255 CreateMockWrite(*req, 0, ASYNC), |
| 255 CreateMockWrite(*rst, 2, ASYNC), | 256 CreateMockWrite(*rst, 2, ASYNC), |
| 256 }; | 257 }; |
| 257 static const char* const kAuthChallenge[] = { | 258 static const char* const kAuthChallenge[] = { |
| 258 ":status", "407 Proxy Authentication Required", | 259 ":status", "407 Proxy Authentication Required", |
| 259 ":version", "HTTP/1.1", | 260 ":version", "HTTP/1.1", |
| 260 "proxy-authenticate", "Basic realm=\"MyRealm1\"", | 261 "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 MockWrite(ASYNC, 0, | 339 MockWrite(ASYNC, 0, |
| 339 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 340 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 340 "Host: www.google.com\r\n" | 341 "Host: www.google.com\r\n" |
| 341 "Proxy-Connection: keep-alive\r\n" | 342 "Proxy-Connection: keep-alive\r\n" |
| 342 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 343 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 343 }; | 344 }; |
| 344 MockRead reads[] = { | 345 MockRead reads[] = { |
| 345 MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), | 346 MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 346 }; | 347 }; |
| 347 | 348 |
| 348 scoped_ptr<SpdyFrame> req(ConstructSpdyConnect(kAuthHeaders, | 349 scoped_ptr<SpdyFrame> req( |
| 349 kAuthHeadersSize, 1)); | 350 spdy_util_.ConstructSpdyConnect(kAuthHeaders, kAuthHeadersSize, 1)); |
| 350 MockWrite spdy_writes[] = { | 351 MockWrite spdy_writes[] = { |
| 351 CreateMockWrite(*req, 0, ASYNC) | 352 CreateMockWrite(*req, 0, ASYNC) |
| 352 }; | 353 }; |
| 353 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 354 scoped_ptr<SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 354 MockRead spdy_reads[] = { | 355 MockRead spdy_reads[] = { |
| 355 CreateMockRead(*resp, 1, ASYNC), | 356 CreateMockRead(*resp, 1, ASYNC), |
| 356 MockRead(ASYNC, 0, 2) | 357 MockRead(ASYNC, 0, 2) |
| 357 }; | 358 }; |
| 358 | 359 |
| 359 Initialize(reads, arraysize(reads), writes, arraysize(writes), | 360 Initialize(reads, arraysize(reads), writes, arraysize(writes), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 MockWrite(ASYNC, 0, | 451 MockWrite(ASYNC, 0, |
| 451 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 452 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 452 "Host: www.google.com\r\n" | 453 "Host: www.google.com\r\n" |
| 453 "Proxy-Connection: keep-alive\r\n" | 454 "Proxy-Connection: keep-alive\r\n" |
| 454 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 455 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 455 }; | 456 }; |
| 456 MockRead reads[] = { | 457 MockRead reads[] = { |
| 457 MockRead(ASYNC, 1, "HTTP/1.1 200 Conn"), | 458 MockRead(ASYNC, 1, "HTTP/1.1 200 Conn"), |
| 458 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2), | 459 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 2), |
| 459 }; | 460 }; |
| 460 scoped_ptr<SpdyFrame> req(ConstructSpdyConnect(kAuthHeaders, | 461 scoped_ptr<SpdyFrame> req( |
| 461 kAuthHeadersSize, 1)); | 462 spdy_util_.ConstructSpdyConnect(kAuthHeaders, kAuthHeadersSize, 1)); |
| 462 MockWrite spdy_writes[] = { | 463 MockWrite spdy_writes[] = { |
| 463 CreateMockWrite(*req, 0, ASYNC) | 464 CreateMockWrite(*req, 0, ASYNC) |
| 464 }; | 465 }; |
| 465 MockRead spdy_reads[] = { | 466 MockRead spdy_reads[] = { |
| 466 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 1), | 467 MockRead(ASYNC, ERR_CONNECTION_CLOSED, 1), |
| 467 }; | 468 }; |
| 468 | 469 |
| 469 Initialize(reads, arraysize(reads), writes, arraysize(writes), | 470 Initialize(reads, arraysize(reads), writes, arraysize(writes), |
| 470 spdy_reads, arraysize(spdy_reads), spdy_writes, | 471 spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 471 arraysize(spdy_writes)); | 472 arraysize(spdy_writes)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 487 MockWrite writes[] = { | 488 MockWrite writes[] = { |
| 488 MockWrite(ASYNC, 0, | 489 MockWrite(ASYNC, 0, |
| 489 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 490 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 490 "Host: www.google.com\r\n" | 491 "Host: www.google.com\r\n" |
| 491 "Proxy-Connection: keep-alive\r\n" | 492 "Proxy-Connection: keep-alive\r\n" |
| 492 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 493 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 493 }; | 494 }; |
| 494 MockRead reads[] = { | 495 MockRead reads[] = { |
| 495 MockRead(ASYNC, 1, "HTTP/1.1 304 Not Modified\r\n\r\n"), | 496 MockRead(ASYNC, 1, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 496 }; | 497 }; |
| 497 scoped_ptr<SpdyFrame> req(ConstructSpdyConnect(kAuthHeaders, | 498 scoped_ptr<SpdyFrame> req( |
| 498 kAuthHeadersSize, 1)); | 499 spdy_util_.ConstructSpdyConnect(kAuthHeaders, kAuthHeadersSize, 1)); |
| 499 scoped_ptr<SpdyFrame> rst( | 500 scoped_ptr<SpdyFrame> rst( |
| 500 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 501 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 501 MockWrite spdy_writes[] = { | 502 MockWrite spdy_writes[] = { |
| 502 CreateMockWrite(*req, 0, ASYNC), | 503 CreateMockWrite(*req, 0, ASYNC), |
| 503 CreateMockWrite(*rst, 2, ASYNC), | 504 CreateMockWrite(*rst, 2, ASYNC), |
| 504 }; | 505 }; |
| 505 scoped_ptr<SpdyFrame> resp(ConstructSpdySynReplyError(1)); | 506 scoped_ptr<SpdyFrame> resp(ConstructSpdySynReplyError(1)); |
| 506 MockRead spdy_reads[] = { | 507 MockRead spdy_reads[] = { |
| 507 CreateMockRead(*resp, 1, ASYNC), | 508 CreateMockRead(*resp, 1, ASYNC), |
| 508 MockRead(ASYNC, 0, 3), | 509 MockRead(ASYNC, 0, 3), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 539 MockWrite(ASYNC, 0, | 540 MockWrite(ASYNC, 0, |
| 540 "CONNECT www.google.com:443 HTTP/1.1\r\n" | 541 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 541 "Host: www.google.com\r\n" | 542 "Host: www.google.com\r\n" |
| 542 "Proxy-Connection: keep-alive\r\n" | 543 "Proxy-Connection: keep-alive\r\n" |
| 543 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 544 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 544 }; | 545 }; |
| 545 MockRead reads[] = { | 546 MockRead reads[] = { |
| 546 MockRead(ASYNC, 1, responseText.c_str()), | 547 MockRead(ASYNC, 1, responseText.c_str()), |
| 547 }; | 548 }; |
| 548 scoped_ptr<SpdyFrame> req( | 549 scoped_ptr<SpdyFrame> req( |
| 549 ConstructSpdyConnect(kAuthHeaders, kAuthHeadersSize, 1)); | 550 spdy_util_.ConstructSpdyConnect(kAuthHeaders, kAuthHeadersSize, 1)); |
| 550 scoped_ptr<SpdyFrame> rst( | 551 scoped_ptr<SpdyFrame> rst( |
| 551 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 552 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 552 | 553 |
| 553 MockWrite spdy_writes[] = { | 554 MockWrite spdy_writes[] = { |
| 554 CreateMockWrite(*req, 0, ASYNC), | 555 CreateMockWrite(*req, 0, ASYNC), |
| 555 }; | 556 }; |
| 556 | 557 |
| 557 const char* const responseHeaders[] = { | 558 const char* const responseHeaders[] = { |
| 558 "location", redirectTarget.c_str(), | 559 "location", redirectTarget.c_str(), |
| 559 "set-cookie", "foo=bar", | 560 "set-cookie", "foo=bar", |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 // Make sure Location header was included and correct. | 609 // Make sure Location header was included and correct. |
| 609 std::string location; | 610 std::string location; |
| 610 EXPECT_TRUE(headers->IsRedirect(&location)); | 611 EXPECT_TRUE(headers->IsRedirect(&location)); |
| 611 EXPECT_EQ(location, redirectTarget); | 612 EXPECT_EQ(location, redirectTarget); |
| 612 } | 613 } |
| 613 } | 614 } |
| 614 | 615 |
| 615 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 616 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 616 | 617 |
| 617 } // namespace net | 618 } // namespace net |
| OLD | NEW |