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 7590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11363 | 11362 |
11364 // SPDY GET for HTTPS URL (through CONNECT tunnel) | 11363 // SPDY GET for HTTPS URL (through CONNECT tunnel) |
11365 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, | 11364 scoped_ptr<SpdyFrame> connect(spdy_util_.ConstructSpdyConnect(NULL, 0, 1, |
11366 LOWEST)); | 11365 LOWEST)); |
11367 scoped_ptr<SpdyFrame> req1( | 11366 scoped_ptr<SpdyFrame> req1( |
11368 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); | 11367 spdy_util_.ConstructSpdyGet(https_url.c_str(), false, 1, LOWEST)); |
11369 scoped_ptr<SpdyFrame> wrapped_req1( | 11368 scoped_ptr<SpdyFrame> wrapped_req1( |
11370 spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); | 11369 spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
11371 | 11370 |
11372 // 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). |
11373 SpdySynStreamIR req2_ir(3); | 11372 SpdyHeaderBlock req2_block; |
11374 spdy_util_.SetPriority(MEDIUM, &req2_ir); | 11373 req2_block[spdy_util_.GetMethodKey()] = "GET"; |
11375 req2_ir.set_fin(true); | 11374 req2_block[spdy_util_.GetPathKey()] = |
11376 req2_ir.SetHeader(spdy_util_.GetMethodKey(), "GET"); | 11375 spdy_util_.is_spdy2() ? http_url.c_str() : "/"; |
11377 req2_ir.SetHeader(spdy_util_.GetPathKey(), | 11376 req2_block[spdy_util_.GetHostKey()] = "www.google.com:443"; |
11378 spdy_util_.is_spdy2() ? http_url.c_str() : "/"); | 11377 req2_block[spdy_util_.GetSchemeKey()] = "http"; |
11379 req2_ir.SetHeader(spdy_util_.GetHostKey(), "www.google.com:443"); | 11378 spdy_util_.MaybeAddVersionHeader(&req2_block); |
11380 req2_ir.SetHeader(spdy_util_.GetSchemeKey(), "http"); | |
11381 spdy_util_.MaybeAddVersionHeader(&req2_ir); | |
11382 scoped_ptr<SpdyFrame> req2( | 11379 scoped_ptr<SpdyFrame> req2( |
11383 spdy_util_.CreateFramer(false)->SerializeFrame(req2_ir)); | 11380 spdy_util_.ConstructSpdySyn(3, req2_block, MEDIUM, false, true)); |
11384 | 11381 |
11385 MockWrite writes1[] = { | 11382 MockWrite writes1[] = { |
11386 CreateMockWrite(*connect, 0), | 11383 CreateMockWrite(*connect, 0), |
11387 CreateMockWrite(*wrapped_req1, 2), | 11384 CreateMockWrite(*wrapped_req1, 2), |
11388 CreateMockWrite(*req2, 5), | 11385 CreateMockWrite(*req2, 5), |
11389 }; | 11386 }; |
11390 | 11387 |
11391 scoped_ptr<SpdyFrame> conn_resp( | 11388 scoped_ptr<SpdyFrame> conn_resp( |
11392 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 11389 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
11393 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... |
11544 // the certificate does not match the new origin. | 11541 // the certificate does not match the new origin. |
11545 // http://crbug.com/134690 | 11542 // http://crbug.com/134690 |
11546 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { | 11543 TEST_P(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
11547 const std::string url1 = "http://www.google.com/"; | 11544 const std::string url1 = "http://www.google.com/"; |
11548 const std::string url2 = "https://mail.google.com/"; | 11545 const std::string url2 = "https://mail.google.com/"; |
11549 const std::string ip_addr = "1.2.3.4"; | 11546 const std::string ip_addr = "1.2.3.4"; |
11550 | 11547 |
11551 // SPDY GET for HTTP URL (through SPDY proxy) | 11548 // SPDY GET for HTTP URL (through SPDY proxy) |
11552 scoped_ptr<SpdyHeaderBlock> headers( | 11549 scoped_ptr<SpdyHeaderBlock> headers( |
11553 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); | 11550 spdy_util_.ConstructGetHeaderBlockForProxy("http://www.google.com/")); |
11554 scoped_ptr<SpdyFrame> req1(spdy_util_.ConstructSpdyControlFrame( | 11551 scoped_ptr<SpdyFrame> req1( |
11555 headers.Pass(), false, 1, LOWEST, SYN_STREAM, CONTROL_FLAG_FIN, 0)); | 11552 spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
11556 | 11553 |
11557 MockWrite writes1[] = { | 11554 MockWrite writes1[] = { |
11558 CreateMockWrite(*req1, 0), | 11555 CreateMockWrite(*req1, 0), |
11559 }; | 11556 }; |
11560 | 11557 |
11561 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 11558 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
11562 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 11559 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
11563 MockRead reads1[] = { | 11560 MockRead reads1[] = { |
11564 CreateMockRead(*resp1, 1), | 11561 CreateMockRead(*resp1, 1), |
11565 CreateMockRead(*body1, 2), | 11562 CreateMockRead(*body1, 2), |
(...skipping 1604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13170 EXPECT_EQ(ERR_IO_PENDING, rv); | 13167 EXPECT_EQ(ERR_IO_PENDING, rv); |
13171 | 13168 |
13172 rv = callback.WaitForResult(); | 13169 rv = callback.WaitForResult(); |
13173 EXPECT_EQ(ERR_CONNECTION_RESET, rv); | 13170 EXPECT_EQ(ERR_CONNECTION_RESET, rv); |
13174 | 13171 |
13175 const HttpResponseInfo* response = trans->GetResponseInfo(); | 13172 const HttpResponseInfo* response = trans->GetResponseInfo(); |
13176 EXPECT_TRUE(response == NULL); | 13173 EXPECT_TRUE(response == NULL); |
13177 } | 13174 } |
13178 | 13175 |
13179 } // namespace net | 13176 } // namespace net |
OLD | NEW |