| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/spdy/spdy_test_util_common.h" | 5 #include "net/spdy/spdy_test_util_common.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstddef> | 9 #include <cstddef> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 // cancellable TCPConnectJobs, use synchronous lookups. | 356 // cancellable TCPConnectJobs, use synchronous lookups. |
| 357 host_resolver->set_synchronous_mode(true); | 357 host_resolver->set_synchronous_mode(true); |
| 358 http2_settings[SETTINGS_INITIAL_WINDOW_SIZE] = kDefaultInitialWindowSize; | 358 http2_settings[SETTINGS_INITIAL_WINDOW_SIZE] = kDefaultInitialWindowSize; |
| 359 } | 359 } |
| 360 | 360 |
| 361 SpdySessionDependencies::~SpdySessionDependencies() {} | 361 SpdySessionDependencies::~SpdySessionDependencies() {} |
| 362 | 362 |
| 363 // static | 363 // static |
| 364 std::unique_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession( | 364 std::unique_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession( |
| 365 SpdySessionDependencies* session_deps) { | 365 SpdySessionDependencies* session_deps) { |
| 366 return SpdyCreateSessionWithSocketFactory(session_deps, |
| 367 session_deps->socket_factory.get()); |
| 368 } |
| 369 |
| 370 // static |
| 371 std::unique_ptr<HttpNetworkSession> |
| 372 SpdySessionDependencies::SpdyCreateSessionWithSocketFactory( |
| 373 SpdySessionDependencies* session_deps, |
| 374 ClientSocketFactory* factory) { |
| 366 HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 375 HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
| 367 params.client_socket_factory = session_deps->socket_factory.get(); | 376 params.client_socket_factory = factory; |
| 368 std::unique_ptr<HttpNetworkSession> http_session( | 377 std::unique_ptr<HttpNetworkSession> http_session( |
| 369 new HttpNetworkSession(params)); | 378 new HttpNetworkSession(params)); |
| 370 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); | 379 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); |
| 371 pool_peer.SetEnableSendingInitialData(false); | 380 pool_peer.SetEnableSendingInitialData(false); |
| 372 return http_session; | 381 return http_session; |
| 373 } | 382 } |
| 374 | 383 |
| 375 // static | 384 // static |
| 376 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( | 385 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( |
| 377 SpdySessionDependencies* session_deps) { | 386 SpdySessionDependencies* session_deps) { |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 685 |
| 677 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, | 686 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, |
| 678 SpdyHeaderBlock* headers) const { | 687 SpdyHeaderBlock* headers) const { |
| 679 std::string scheme, host, path; | 688 std::string scheme, host, path; |
| 680 ParseUrl(url, &scheme, &host, &path); | 689 ParseUrl(url, &scheme, &host, &path); |
| 681 (*headers)[GetHostKey()] = host; | 690 (*headers)[GetHostKey()] = host; |
| 682 (*headers)[GetSchemeKey()] = scheme; | 691 (*headers)[GetSchemeKey()] = scheme; |
| 683 (*headers)[GetPathKey()] = path; | 692 (*headers)[GetPathKey()] = path; |
| 684 } | 693 } |
| 685 | 694 |
| 686 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlock( | 695 // static |
| 687 base::StringPiece url) const { | 696 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlock(base::StringPiece url) { |
| 688 return ConstructHeaderBlock("GET", url, NULL); | 697 return ConstructHeaderBlock("GET", url, NULL); |
| 689 } | 698 } |
| 690 | 699 |
| 700 // static |
| 691 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlockForProxy( | 701 SpdyHeaderBlock SpdyTestUtil::ConstructGetHeaderBlockForProxy( |
| 692 base::StringPiece url) const { | 702 base::StringPiece url) { |
| 693 return ConstructGetHeaderBlock(url); | 703 return ConstructGetHeaderBlock(url); |
| 694 } | 704 } |
| 695 | 705 |
| 696 SpdyHeaderBlock SpdyTestUtil::ConstructHeadHeaderBlock( | 706 // static |
| 697 base::StringPiece url, | 707 SpdyHeaderBlock SpdyTestUtil::ConstructHeadHeaderBlock(base::StringPiece url, |
| 698 int64_t content_length) const { | 708 int64_t content_length) { |
| 699 return ConstructHeaderBlock("HEAD", url, nullptr); | 709 return ConstructHeaderBlock("HEAD", url, nullptr); |
| 700 } | 710 } |
| 701 | 711 |
| 702 SpdyHeaderBlock SpdyTestUtil::ConstructPostHeaderBlock( | 712 // static |
| 703 base::StringPiece url, | 713 SpdyHeaderBlock SpdyTestUtil::ConstructPostHeaderBlock(base::StringPiece url, |
| 704 int64_t content_length) const { | 714 int64_t content_length) { |
| 705 return ConstructHeaderBlock("POST", url, &content_length); | 715 return ConstructHeaderBlock("POST", url, &content_length); |
| 706 } | 716 } |
| 707 | 717 |
| 708 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock( | 718 // static |
| 709 base::StringPiece url, | 719 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock(base::StringPiece url, |
| 710 int64_t content_length) const { | 720 int64_t content_length) { |
| 711 return ConstructHeaderBlock("PUT", url, &content_length); | 721 return ConstructHeaderBlock("PUT", url, &content_length); |
| 712 } | 722 } |
| 713 | 723 |
| 714 std::string SpdyTestUtil::ConstructSpdyReplyString( | 724 std::string SpdyTestUtil::ConstructSpdyReplyString( |
| 715 const SpdyHeaderBlock& headers) const { | 725 const SpdyHeaderBlock& headers) const { |
| 716 std::string reply_string; | 726 std::string reply_string; |
| 717 for (SpdyHeaderBlock::const_iterator it = headers.begin(); | 727 for (SpdyHeaderBlock::const_iterator it = headers.begin(); |
| 718 it != headers.end(); ++it) { | 728 it != headers.end(); ++it) { |
| 719 std::string key = it->first.as_string(); | 729 std::string key = it->first.as_string(); |
| 720 // Remove leading colon from pseudo headers. | 730 // Remove leading colon from pseudo headers. |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1087 stream_it != priority_it->second.end(); ++stream_it) { | 1097 stream_it != priority_it->second.end(); ++stream_it) { |
| 1088 if (*stream_it == stream_id) { | 1098 if (*stream_it == stream_id) { |
| 1089 priority_it->second.erase(stream_it); | 1099 priority_it->second.erase(stream_it); |
| 1090 return; | 1100 return; |
| 1091 } | 1101 } |
| 1092 } | 1102 } |
| 1093 } | 1103 } |
| 1094 NOTREACHED(); | 1104 NOTREACHED(); |
| 1095 } | 1105 } |
| 1096 | 1106 |
| 1097 const char* SpdyTestUtil::GetMethodKey() const { | 1107 // static |
| 1108 const char* SpdyTestUtil::GetMethodKey() { |
| 1098 return ":method"; | 1109 return ":method"; |
| 1099 } | 1110 } |
| 1100 | 1111 |
| 1101 const char* SpdyTestUtil::GetStatusKey() const { | 1112 // static |
| 1113 const char* SpdyTestUtil::GetStatusKey() { |
| 1102 return ":status"; | 1114 return ":status"; |
| 1103 } | 1115 } |
| 1104 | 1116 |
| 1105 const char* SpdyTestUtil::GetHostKey() const { | 1117 // static |
| 1118 const char* SpdyTestUtil::GetHostKey() { |
| 1106 return ":authority"; | 1119 return ":authority"; |
| 1107 } | 1120 } |
| 1108 | 1121 |
| 1109 const char* SpdyTestUtil::GetSchemeKey() const { | 1122 // static |
| 1123 const char* SpdyTestUtil::GetSchemeKey() { |
| 1110 return ":scheme"; | 1124 return ":scheme"; |
| 1111 } | 1125 } |
| 1112 | 1126 |
| 1113 const char* SpdyTestUtil::GetPathKey() const { | 1127 // static |
| 1128 const char* SpdyTestUtil::GetPathKey() { |
| 1114 return ":path"; | 1129 return ":path"; |
| 1115 } | 1130 } |
| 1116 | 1131 |
| 1117 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock( | 1132 // static |
| 1118 base::StringPiece method, | 1133 SpdyHeaderBlock SpdyTestUtil::ConstructHeaderBlock(base::StringPiece method, |
| 1119 base::StringPiece url, | 1134 base::StringPiece url, |
| 1120 int64_t* content_length) const { | 1135 int64_t* content_length) { |
| 1121 std::string scheme, host, path; | 1136 std::string scheme, host, path; |
| 1122 ParseUrl(url, &scheme, &host, &path); | 1137 ParseUrl(url, &scheme, &host, &path); |
| 1123 SpdyHeaderBlock headers; | 1138 SpdyHeaderBlock headers; |
| 1124 headers[GetMethodKey()] = method.as_string(); | 1139 headers[GetMethodKey()] = method.as_string(); |
| 1125 headers[GetHostKey()] = host.c_str(); | 1140 headers[GetHostKey()] = host.c_str(); |
| 1126 headers[GetSchemeKey()] = scheme.c_str(); | 1141 headers[GetSchemeKey()] = scheme.c_str(); |
| 1127 headers[GetPathKey()] = path.c_str(); | 1142 headers[GetPathKey()] = path.c_str(); |
| 1128 if (content_length) { | 1143 if (content_length) { |
| 1129 std::string length_str = base::Int64ToString(*content_length); | 1144 std::string length_str = base::Int64ToString(*content_length); |
| 1130 headers["content-length"] = length_str; | 1145 headers["content-length"] = length_str; |
| 1131 } | 1146 } |
| 1132 return headers; | 1147 return headers; |
| 1133 } | 1148 } |
| 1134 | 1149 |
| 1135 } // namespace net | 1150 } // namespace net |
| OLD | NEW |