| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdarg.h> | 8 #include <stdarg.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 3467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3478 const char resp1[] = "HTTP/1.1 200 OK\r\n" | 3478 const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 3479 "Content-Length: 1\r\n\r\n"; | 3479 "Content-Length: 1\r\n\r\n"; |
| 3480 scoped_ptr<SpdyFrame> wrapped_get_resp1( | 3480 scoped_ptr<SpdyFrame> wrapped_get_resp1( |
| 3481 spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); | 3481 spdy_util_.ConstructSpdyBodyFrame(1, resp1, strlen(resp1), false)); |
| 3482 scoped_ptr<SpdyFrame> wrapped_body1( | 3482 scoped_ptr<SpdyFrame> wrapped_body1( |
| 3483 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); | 3483 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, false)); |
| 3484 scoped_ptr<SpdyFrame> window_update( | 3484 scoped_ptr<SpdyFrame> window_update( |
| 3485 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); | 3485 spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1->size())); |
| 3486 | 3486 |
| 3487 // CONNECT to news.google.com:443 via SPDY. | 3487 // CONNECT to news.google.com:443 via SPDY. |
| 3488 SpdySynStreamIR connect2_ir(3); | 3488 SpdyHeaderBlock connect2_block; |
| 3489 spdy_util_.SetPriority(LOWEST, &connect2_ir); | 3489 connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
| 3490 connect2_ir.SetHeader(spdy_util_.GetMethodKey(), "CONNECT"); | 3490 connect2_block[spdy_util_.GetPathKey()] = "news.google.com:443"; |
| 3491 connect2_ir.SetHeader(spdy_util_.GetPathKey(), "news.google.com:443"); | 3491 connect2_block[spdy_util_.GetHostKey()] = "news.google.com"; |
| 3492 connect2_ir.SetHeader(spdy_util_.GetHostKey(), "news.google.com"); | 3492 spdy_util_.MaybeAddVersionHeader(&connect2_block); |
| 3493 spdy_util_.MaybeAddVersionHeader(&connect2_ir); | |
| 3494 scoped_ptr<SpdyFrame> connect2( | 3493 scoped_ptr<SpdyFrame> connect2( |
| 3495 spdy_util_.CreateFramer(false)->SerializeFrame(connect2_ir)); | 3494 spdy_util_.ConstructSpdySyn(3, connect2_block, LOWEST, false, false)); |
| 3496 | 3495 |
| 3497 scoped_ptr<SpdyFrame> conn_resp2( | 3496 scoped_ptr<SpdyFrame> conn_resp2( |
| 3498 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 3497 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3499 | 3498 |
| 3500 // Fetch https://news.google.com/ via HTTP. | 3499 // Fetch https://news.google.com/ via HTTP. |
| 3501 const char get2[] = "GET / HTTP/1.1\r\n" | 3500 const char get2[] = "GET / HTTP/1.1\r\n" |
| 3502 "Host: news.google.com\r\n" | 3501 "Host: news.google.com\r\n" |
| 3503 "Connection: keep-alive\r\n\r\n"; | 3502 "Connection: keep-alive\r\n\r\n"; |
| 3504 scoped_ptr<SpdyFrame> wrapped_get2( | 3503 scoped_ptr<SpdyFrame> wrapped_get2( |
| 3505 spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); | 3504 spdy_util_.ConstructSpdyBodyFrame(3, get2, strlen(get2), false)); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3741 request1.load_flags = 0; | 3740 request1.load_flags = 0; |
| 3742 | 3741 |
| 3743 HttpRequestInfo request2; | 3742 HttpRequestInfo request2; |
| 3744 request2.method = "GET"; | 3743 request2.method = "GET"; |
| 3745 request2.url = GURL("http://news.google.com/"); | 3744 request2.url = GURL("http://news.google.com/"); |
| 3746 request2.load_flags = 0; | 3745 request2.load_flags = 0; |
| 3747 | 3746 |
| 3748 // http://www.google.com/ | 3747 // http://www.google.com/ |
| 3749 scoped_ptr<SpdyHeaderBlock> headers( | 3748 scoped_ptr<SpdyHeaderBlock> headers( |
| 3750 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); | 3749 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
| 3751 scoped_ptr<SpdyFrame> get1(spdy_util_.ConstructSpdyControlFrame( | 3750 scoped_ptr<SpdyFrame> get1( |
| 3752 headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); | 3751 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 3753 scoped_ptr<SpdyFrame> get_resp1( | 3752 scoped_ptr<SpdyFrame> get_resp1( |
| 3754 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3753 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3755 scoped_ptr<SpdyFrame> body1( | 3754 scoped_ptr<SpdyFrame> body1( |
| 3756 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); | 3755 spdy_util_.ConstructSpdyBodyFrame(1, "1", 1, true)); |
| 3757 | 3756 |
| 3758 // http://news.google.com/ | 3757 // http://news.google.com/ |
| 3759 scoped_ptr<SpdyHeaderBlock> headers2( | 3758 scoped_ptr<SpdyHeaderBlock> headers2( |
| 3760 spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); | 3759 spdy_util_.ConstructGetHeaderBlockForProxy("http://news.google.com/")); |
| 3761 scoped_ptr<SpdyFrame> get2(spdy_util_.ConstructSpdyControlFrame( | 3760 scoped_ptr<SpdyFrame> get2( |
| 3762 headers2.Pass(), false, 3, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); | 3761 spdy_util_.ConstructSpdySyn(3, *headers2, LOWEST, false, true)); |
| 3763 scoped_ptr<SpdyFrame> get_resp2( | 3762 scoped_ptr<SpdyFrame> get_resp2( |
| 3764 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 3763 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3765 scoped_ptr<SpdyFrame> body2( | 3764 scoped_ptr<SpdyFrame> body2( |
| 3766 spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); | 3765 spdy_util_.ConstructSpdyBodyFrame(3, "22", 2, true)); |
| 3767 | 3766 |
| 3768 MockWrite spdy_writes[] = { | 3767 MockWrite spdy_writes[] = { |
| 3769 CreateMockWrite(*get1, 0), | 3768 CreateMockWrite(*get1, 0), |
| 3770 CreateMockWrite(*get2, 3), | 3769 CreateMockWrite(*get2, 3), |
| 3771 }; | 3770 }; |
| 3772 | 3771 |
| (...skipping 2608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6381 | 6380 |
| 6382 MockWrite spdy_writes[] = { | 6381 MockWrite spdy_writes[] = { |
| 6383 CreateMockWrite(*req, 1, ASYNC), | 6382 CreateMockWrite(*req, 1, ASYNC), |
| 6384 CreateMockWrite(*rst, 4, ASYNC), | 6383 CreateMockWrite(*rst, 4, ASYNC), |
| 6385 CreateMockWrite(*connect2, 5), | 6384 CreateMockWrite(*connect2, 5), |
| 6386 CreateMockWrite(*wrapped_get, 8), | 6385 CreateMockWrite(*wrapped_get, 8), |
| 6387 }; | 6386 }; |
| 6388 | 6387 |
| 6389 // The proxy responds to the connect with a 407, using a persistent | 6388 // The proxy responds to the connect with a 407, using a persistent |
| 6390 // connection. | 6389 // connection. |
| 6390 const char* const kAuthStatus = "407"; |
| 6391 const char* const kAuthChallenge[] = { | 6391 const char* const kAuthChallenge[] = { |
| 6392 spdy_util_.GetStatusKey(), "407 Proxy Authentication Required", | |
| 6393 spdy_util_.GetVersionKey(), "HTTP/1.1", | |
| 6394 "proxy-authenticate", "Basic realm=\"MyRealm1\"", | 6392 "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 6395 }; | 6393 }; |
| 6396 | 6394 scoped_ptr<SpdyFrame> conn_auth_resp(spdy_util_.ConstructSpdySynReplyError( |
| 6397 scoped_ptr<SpdyFrame> conn_auth_resp( | 6395 kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
| 6398 spdy_util_.ConstructSpdyControlFrame(NULL, | |
| 6399 0, | |
| 6400 false, | |
| 6401 1, | |
| 6402 LOWEST, | |
| 6403 SYN_REPLY, | |
| 6404 CONTROL_FLAG_NONE, | |
| 6405 kAuthChallenge, | |
| 6406 arraysize(kAuthChallenge), | |
| 6407 0)); | |
| 6408 | 6396 |
| 6409 scoped_ptr<SpdyFrame> conn_resp( | 6397 scoped_ptr<SpdyFrame> conn_resp( |
| 6410 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 6398 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 6411 const char resp[] = "HTTP/1.1 200 OK\r\n" | 6399 const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 6412 "Content-Length: 5\r\n\r\n"; | 6400 "Content-Length: 5\r\n\r\n"; |
| 6413 | 6401 |
| 6414 scoped_ptr<SpdyFrame> wrapped_get_resp( | 6402 scoped_ptr<SpdyFrame> wrapped_get_resp( |
| 6415 spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); | 6403 spdy_util_.ConstructSpdyBodyFrame(3, resp, strlen(resp), false)); |
| 6416 scoped_ptr<SpdyFrame> wrapped_body( | 6404 scoped_ptr<SpdyFrame> wrapped_body( |
| 6417 spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); | 6405 spdy_util_.ConstructSpdyBodyFrame(3, "hello", 5, false)); |
| (...skipping 4956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11374 | 11362 |
| 11375 // SPDY GET for HTTPS URL (through CONNECT tunnel) | 11363 // SPDY GET for HTTPS URL (through CONNECT tunnel) |
| 11376 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, | 11364 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
| 11377 LOWEST)); | 11365 LOWEST)); |
| 11378 scoped_ptr<SpdyFrame> req1( | 11366 scoped_ptr<SpdyFrame> req1( |
| 11379 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | 11367 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
| 11380 scoped_ptr<SpdyFrame> wrapped_req1( | 11368 scoped_ptr<SpdyFrame> wrapped_req1( |
| 11381 spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); | 11369 spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
| 11382 | 11370 |
| 11383 // SPDY GET for HTTP URL (through the proxy, but not the tunnel). | 11371 // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
| 11384 SpdySynStreamIR req2_ir(3); | 11372 SpdyHeaderBlock req2_block; |
| 11385 spdy_util_.SetPriority(MEDIUM, &req2_ir); | 11373 req2_block[spdy_util_.GetMethodKey()] = "GET"; |
| 11386 req2_ir.set_fin(true); | 11374 req2_block[spdy_util_.GetPathKey()] = |
| 11387 req2_ir.SetHeader(spdy_util_.GetMethodKey(), "GET"); | 11375 spdy_util_.is_spdy2() ? http_url.c_str() : "/"; |
| 11388 req2_ir.SetHeader(spdy_util_.GetPathKey(), | 11376 req2_block[spdy_util_.GetHostKey()] = "www.google.com:443"; |
| 11389 spdy_util_.is_spdy2() ? http_url.c_str() : "/"); | 11377 req2_block[spdy_util_.GetSchemeKey()] = "http"; |
| 11390 req2_ir.SetHeader(spdy_util_.GetHostKey(), "www.google.com:443"); | 11378 spdy_util_.MaybeAddVersionHeader(&req2_block); |
| 11391 req2_ir.SetHeader(spdy_util_.GetSchemeKey(), "http"); | |
| 11392 spdy_util_.MaybeAddVersionHeader(&req2_ir); | |
| 11393 scoped_ptr<SpdyFrame> req2( | 11379 scoped_ptr<SpdyFrame> req2( |
| 11394 spdy_util_.CreateFramer(false)->SerializeFrame(req2_ir)); | 11380 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
| 11395 | 11381 |
| 11396 MockWrite writes1[] = { | 11382 MockWrite writes1[] = { |
| 11397 CreateMockWrite(*connect, 0), | 11383 CreateMockWrite(*connect, 0), |
| 11398 CreateMockWrite(*wrapped_req1, 2), | 11384 CreateMockWrite(*wrapped_req1, 2), |
| 11399 CreateMockWrite(*req2, 5), | 11385 CreateMockWrite(*req2, 5), |
| 11400 }; | 11386 }; |
| 11401 | 11387 |
| 11402 scoped_ptr<SpdyFrame> conn_resp( | 11388 scoped_ptr<SpdyFrame> conn_resp( |
| 11403 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 11389 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11404 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 11390 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11555 // the certificate does not match the new origin. | 11541 // the certificate does not match the new origin. |
| 11556 // http://crbug.com/134690 | 11542 // http://crbug.com/134690 |
| 11557 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { | 11543 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
| 11558 const std::string url1 = "http://www.google.com/"; | 11544 const std::string url1 = "http://www.google.com/"; |
| 11559 const std::string url2 = "https://mail.google.com/"; | 11545 const std::string url2 = "https://mail.google.com/"; |
| 11560 const std::string ip_addr = "1.2.3.4"; | 11546 const std::string ip_addr = "1.2.3.4"; |
| 11561 | 11547 |
| 11562 // SPDY GET for HTTP URL (through SPDY proxy) | 11548 // SPDY GET for HTTP URL (through SPDY proxy) |
| 11563 scoped_ptr<SpdyHeaderBlock> headers( | 11549 scoped_ptr<SpdyHeaderBlock> headers( |
| 11564 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); | 11550 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
| 11565 scoped_ptr<SpdyFrame> req1(spdy_util_.ConstructSpdyControlFrame( | 11551 scoped_ptr<SpdyFrame> req1( |
| 11566 headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); | 11552 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 11567 | 11553 |
| 11568 MockWrite writes1[] = { | 11554 MockWrite writes1[] = { |
| 11569 CreateMockWrite(*req1, 0), | 11555 CreateMockWrite(*req1, 0), |
| 11570 }; | 11556 }; |
| 11571 | 11557 |
| 11572 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 11558 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 11573 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 11559 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 11574 MockRead reads1[] = { | 11560 MockRead reads1[] = { |
| 11575 CreateMockRead(*resp1, 1), | 11561 CreateMockRead(*resp1, 1), |
| 11576 CreateMockRead(*body1, 2), | 11562 CreateMockRead(*body1, 2), |
| (...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13181 EXPECT_EQ(ERR_IO_PENDING, rv); | 13167 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 13182 | 13168 |
| 13183 rv = callback.WaitForResult(); | 13169 rv = callback.WaitForResult(); |
| 13184 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13170 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
| 13185 | 13171 |
| 13186 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13172 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13187 EXPECT_TRUE(response == NULL); | 13173 EXPECT_TRUE(response == NULL); |
| 13188 } | 13174 } |
| 13189 | 13175 |
| 13190 } // namespace net | 13176 } // namespace net |
| OLD | NEW |