OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2268 ssl2.next_proto = "spdy/2"; | 2268 ssl2.next_proto = "spdy/2"; |
2269 ssl2.was_npn_negotiated = true; | 2269 ssl2.was_npn_negotiated = true; |
2270 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2); | 2270 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl2); |
2271 | 2271 |
2272 TestCompletionCallback callback1; | 2272 TestCompletionCallback callback1; |
2273 | 2273 |
2274 int rv = trans->Start(&request, &callback1, log.bound()); | 2274 int rv = trans->Start(&request, &callback1, log.bound()); |
2275 EXPECT_EQ(ERR_IO_PENDING, rv); | 2275 EXPECT_EQ(ERR_IO_PENDING, rv); |
2276 | 2276 |
2277 rv = callback1.WaitForResult(); | 2277 rv = callback1.WaitForResult(); |
2278 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, rv); | 2278 EXPECT_EQ(OK, rv); |
2279 | 2279 |
2280 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2280 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2281 ASSERT_TRUE(response == NULL); | 2281 ASSERT_FALSE(response == NULL); |
2282 EXPECT_EQ(500, response->headers->response_code()); | |
2282 } | 2283 } |
2283 | 2284 |
2284 // Test the challenge-response-retry sequence through an HTTPS Proxy | 2285 // Test the challenge-response-retry sequence through an HTTPS Proxy |
2285 TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { | 2286 TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
2286 // Configure against https proxy server "proxy:70". | 2287 // Configure against https proxy server "proxy:70". |
2287 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | 2288 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); |
2288 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 2289 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
2289 session_deps.net_log = log.bound().net_log(); | 2290 session_deps.net_log = log.bound().net_log(); |
2290 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 2291 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
2291 | 2292 |
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4459 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4460 const HttpResponseInfo* response = trans->GetResponseInfo(); |
4460 | 4461 |
4461 ASSERT_FALSE(response == NULL); | 4462 ASSERT_FALSE(response == NULL); |
4462 | 4463 |
4463 EXPECT_TRUE(response->headers->IsKeepAlive()); | 4464 EXPECT_TRUE(response->headers->IsKeepAlive()); |
4464 EXPECT_EQ(200, response->headers->response_code()); | 4465 EXPECT_EQ(200, response->headers->response_code()); |
4465 EXPECT_EQ(100, response->headers->GetContentLength()); | 4466 EXPECT_EQ(100, response->headers->GetContentLength()); |
4466 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | 4467 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
4467 } | 4468 } |
4468 | 4469 |
4470 // Test an HTTPS Proxy's ability to redirect a CONNECT request | |
4471 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { | |
4472 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | |
willchan no longer on Chromium
2010/12/14 00:34:42
80 columns :)
Ryan Hamilton
2010/12/15 20:14:17
Done. I wonder why the pre-commit check didn't wa
| |
4473 | |
4474 HttpRequestInfo request; | |
4475 request.method = "GET"; | |
4476 request.url = GURL("https://www.google.com/"); | |
4477 request.load_flags = 0; | |
4478 | |
4479 MockWrite data_writes[] = { | |
4480 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
4481 "Host: www.google.com\r\n" | |
4482 "Proxy-Connection: keep-alive\r\n\r\n"), | |
4483 }; | |
4484 | |
4485 MockRead data_reads[] = { | |
4486 MockRead("HTTP/1.1 302 Redirect\r\n"), | |
4487 MockRead("Location: http://login.example.com/\r\n"), | |
4488 MockRead("Content-Length: 0\r\n\r\n"), | |
4489 MockRead(false, OK), | |
4490 }; | |
4491 | |
4492 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
4493 data_writes, arraysize(data_writes)); | |
4494 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4495 | |
4496 session_deps.socket_factory.AddSocketDataProvider(&data); | |
4497 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4498 | |
4499 TestCompletionCallback callback; | |
4500 | |
4501 scoped_ptr<HttpTransaction> trans( | |
4502 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4503 | |
4504 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4505 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4506 | |
4507 rv = callback.WaitForResult(); | |
4508 EXPECT_EQ(OK, rv); | |
4509 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4510 | |
4511 ASSERT_FALSE(response == NULL); | |
4512 | |
4513 EXPECT_EQ(302, response->headers->response_code()); | |
4514 std::string url; | |
4515 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
4516 EXPECT_EQ("http://login.example.com/", url); | |
4517 } | |
4518 | |
4519 // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request | |
4520 TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { | |
4521 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | |
willchan no longer on Chromium
2010/12/14 00:34:42
80 columns :)
Ryan Hamilton
2010/12/15 20:14:17
Done.
| |
4522 | |
4523 HttpRequestInfo request; | |
4524 request.method = "GET"; | |
4525 request.url = GURL("https://www.google.com/"); | |
4526 request.load_flags = 0; | |
4527 | |
4528 scoped_ptr<spdy::SpdyFrame> conn(ConstructSpdyConnect(NULL, 0, 1)); | |
4529 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyRstStream(1, spdy::CANCEL)); | |
4530 MockWrite data_writes[] = { | |
4531 CreateMockWrite(*conn.get(), 0, false), | |
4532 }; | |
4533 | |
4534 static const char* const kExtraHeaders[] = { | |
4535 "location", | |
4536 "http://login.example.com/", | |
4537 }; | |
4538 scoped_ptr<spdy::SpdyFrame> resp( | |
4539 ConstructSpdySynReplyError("302 Redirect", kExtraHeaders, | |
4540 arraysize(kExtraHeaders)/2, 1)); | |
4541 MockRead data_reads[] = { | |
4542 CreateMockRead(*resp.get(), 1, false), | |
4543 MockRead(true, 0, 2), // EOF | |
4544 }; | |
4545 | |
4546 scoped_refptr<DelayedSocketData> data( | |
4547 new DelayedSocketData( | |
4548 1, // wait for one write to finish before reading. | |
4549 data_reads, arraysize(data_reads), | |
4550 data_writes, arraysize(data_writes))); | |
4551 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4552 proxy_ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | |
4553 proxy_ssl.next_proto = "spdy/2"; | |
4554 proxy_ssl.was_npn_negotiated = true; | |
4555 | |
4556 session_deps.socket_factory.AddSocketDataProvider(data.get()); | |
4557 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4558 | |
4559 TestCompletionCallback callback; | |
4560 | |
4561 scoped_ptr<HttpTransaction> trans( | |
4562 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4563 | |
4564 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4565 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4566 | |
4567 rv = callback.WaitForResult(); | |
4568 EXPECT_EQ(OK, rv); | |
4569 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4570 | |
4571 ASSERT_FALSE(response == NULL); | |
4572 | |
4573 EXPECT_EQ(302, response->headers->response_code()); | |
4574 std::string url; | |
4575 EXPECT_TRUE(response->headers->IsRedirect(&url)); | |
4576 EXPECT_EQ("http://login.example.com/", url); | |
4577 } | |
4578 | |
4579 // Test an HTTPS Proxy's ability to provide a response to a CONNECT request | |
4580 TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaHttpsProxy) { | |
4581 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | |
willchan no longer on Chromium
2010/12/14 00:34:42
80 columns :)
Ryan Hamilton
2010/12/15 20:14:17
Done.
| |
4582 | |
4583 HttpRequestInfo request; | |
4584 request.method = "GET"; | |
4585 request.url = GURL("https://www.google.com/"); | |
4586 request.load_flags = 0; | |
4587 | |
4588 MockWrite data_writes[] = { | |
4589 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" | |
4590 "Host: www.google.com\r\n" | |
4591 "Proxy-Connection: keep-alive\r\n\r\n"), | |
4592 }; | |
4593 | |
4594 MockRead data_reads[] = { | |
4595 MockRead("HTTP/1.1 404 Not Found\r\n"), | |
4596 MockRead("Content-Length: 23\r\n\r\n"), | |
4597 MockRead("The host does not exist"), | |
4598 MockRead(false, OK), | |
4599 }; | |
4600 | |
4601 StaticSocketDataProvider data(data_reads, arraysize(data_reads), | |
4602 data_writes, arraysize(data_writes)); | |
4603 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4604 | |
4605 session_deps.socket_factory.AddSocketDataProvider(&data); | |
4606 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4607 | |
4608 TestCompletionCallback callback; | |
4609 | |
4610 scoped_ptr<HttpTransaction> trans( | |
4611 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4612 | |
4613 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4614 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4615 | |
4616 rv = callback.WaitForResult(); | |
4617 EXPECT_EQ(OK, rv); | |
4618 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4619 | |
4620 ASSERT_FALSE(response == NULL); | |
4621 | |
4622 EXPECT_EQ(404, response->headers->response_code()); | |
4623 EXPECT_EQ(23, response->headers->GetContentLength()); | |
4624 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); | |
4625 | |
4626 std::string response_data; | |
4627 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
4628 EXPECT_EQ("The host does not exist", response_data); | |
4629 } | |
4630 | |
4631 // Test an HTTPS (SPDY) Proxy's ability to provide a response to a CONNECT | |
4632 // request | |
4633 TEST_F(HttpNetworkTransactionTest, ErrorResponseTofHttpsConnectViaSpdyProxy) { | |
4634 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | |
willchan no longer on Chromium
2010/12/14 00:34:42
80 columns :)
Ryan Hamilton
2010/12/15 20:14:17
Done.
| |
4635 | |
4636 HttpRequestInfo request; | |
4637 request.method = "GET"; | |
4638 request.url = GURL("https://www.google.com/"); | |
4639 request.load_flags = 0; | |
4640 | |
4641 scoped_ptr<spdy::SpdyFrame> conn(ConstructSpdyConnect(NULL, 0, 1)); | |
4642 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyRstStream(1, spdy::CANCEL)); | |
4643 MockWrite data_writes[] = { | |
4644 CreateMockWrite(*conn.get(), 0, false), | |
4645 }; | |
4646 | |
4647 static const char* const kExtraHeaders[] = { | |
4648 "location", | |
4649 "http://login.example.com/", | |
4650 }; | |
4651 scoped_ptr<spdy::SpdyFrame> resp( | |
4652 ConstructSpdySynReplyError("404 Not Found", kExtraHeaders, | |
4653 arraysize(kExtraHeaders)/2, 1)); | |
4654 scoped_ptr<spdy::SpdyFrame> body( | |
4655 ConstructSpdyBodyFrame(1, "The host does not exist", 23, true)); | |
4656 MockRead data_reads[] = { | |
4657 CreateMockRead(*resp.get(), 1, false), | |
4658 CreateMockRead(*body.get(), 2, false), | |
4659 MockRead(true, 0, 3), // EOF | |
4660 }; | |
4661 | |
4662 scoped_refptr<DelayedSocketData> data( | |
4663 new DelayedSocketData( | |
4664 1, // wait for one write to finish before reading. | |
4665 data_reads, arraysize(data_reads), | |
4666 data_writes, arraysize(data_writes))); | |
4667 SSLSocketDataProvider proxy_ssl(true, OK); // SSL to the proxy | |
4668 proxy_ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated; | |
4669 proxy_ssl.next_proto = "spdy/2"; | |
4670 proxy_ssl.was_npn_negotiated = true; | |
4671 | |
4672 session_deps.socket_factory.AddSocketDataProvider(data.get()); | |
4673 session_deps.socket_factory.AddSSLSocketDataProvider(&proxy_ssl); | |
4674 | |
4675 TestCompletionCallback callback; | |
4676 | |
4677 scoped_ptr<HttpTransaction> trans( | |
4678 new HttpNetworkTransaction(CreateSession(&session_deps))); | |
4679 | |
4680 int rv = trans->Start(&request, &callback, BoundNetLog()); | |
4681 EXPECT_EQ(ERR_IO_PENDING, rv); | |
4682 | |
4683 rv = callback.WaitForResult(); | |
4684 EXPECT_EQ(OK, rv); | |
4685 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
4686 | |
4687 ASSERT_FALSE(response == NULL); | |
4688 | |
4689 EXPECT_EQ(404, response->headers->response_code()); | |
4690 | |
4691 std::string response_data; | |
4692 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | |
4693 EXPECT_EQ("The host does not exist", response_data); | |
4694 } | |
4695 | |
4469 // Test HTTPS connections to a site with a bad certificate, going through an | 4696 // Test HTTPS connections to a site with a bad certificate, going through an |
4470 // HTTPS proxy | 4697 // HTTPS proxy |
4471 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { | 4698 TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
4472 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); | 4699 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70") ); |
4473 | 4700 |
4474 HttpRequestInfo request; | 4701 HttpRequestInfo request; |
4475 request.method = "GET"; | 4702 request.method = "GET"; |
4476 request.url = GURL("https://www.google.com/"); | 4703 request.url = GURL("https://www.google.com/"); |
4477 request.load_flags = 0; | 4704 request.load_flags = 0; |
4478 | 4705 |
(...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7958 rv = callback.WaitForResult(); | 8185 rv = callback.WaitForResult(); |
7959 ASSERT_EQ(OK, rv); | 8186 ASSERT_EQ(OK, rv); |
7960 | 8187 |
7961 std::string contents; | 8188 std::string contents; |
7962 rv = ReadTransaction(trans.get(), &contents); | 8189 rv = ReadTransaction(trans.get(), &contents); |
7963 EXPECT_EQ(net::OK, rv); | 8190 EXPECT_EQ(net::OK, rv); |
7964 EXPECT_EQ("hello world", contents); | 8191 EXPECT_EQ("hello world", contents); |
7965 } | 8192 } |
7966 | 8193 |
7967 } // namespace net | 8194 } // namespace net |
OLD | NEW |