| 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 <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 host->append(":"); | 47 host->append(":"); |
| 48 host->append(gurl.port()); | 48 host->append(gurl.port()); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 NextProtoVector SpdyNextProtos() { | 54 NextProtoVector SpdyNextProtos() { |
| 55 NextProtoVector next_protos; | 55 NextProtoVector next_protos; |
| 56 next_protos.push_back(kProtoHTTP11); | 56 next_protos.push_back(kProtoHTTP11); |
| 57 next_protos.push_back(kProtoDeprecatedSPDY2); | |
| 58 next_protos.push_back(kProtoSPDY3); | |
| 59 next_protos.push_back(kProtoSPDY31); | 57 next_protos.push_back(kProtoSPDY31); |
| 60 next_protos.push_back(kProtoSPDY4_14); | 58 next_protos.push_back(kProtoSPDY4_14); |
| 61 next_protos.push_back(kProtoSPDY4_15); | 59 next_protos.push_back(kProtoSPDY4_15); |
| 62 next_protos.push_back(kProtoQUIC1SPDY3); | 60 next_protos.push_back(kProtoQUIC1SPDY3); |
| 63 return next_protos; | 61 return next_protos; |
| 64 } | 62 } |
| 65 | 63 |
| 66 // Chop a frame into an array of MockWrites. | 64 // Chop a frame into an array of MockWrites. |
| 67 // |data| is the frame to chop. | 65 // |data| is the frame to chop. |
| 68 // |length| is the length of the frame to chop. | 66 // |length| is the length of the frame to chop. |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 } | 711 } |
| 714 | 712 |
| 715 SpdyTestUtil::SpdyTestUtil(NextProto protocol) | 713 SpdyTestUtil::SpdyTestUtil(NextProto protocol) |
| 716 : protocol_(protocol), | 714 : protocol_(protocol), |
| 717 spdy_version_(NextProtoToSpdyMajorVersion(protocol)) { | 715 spdy_version_(NextProtoToSpdyMajorVersion(protocol)) { |
| 718 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 716 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
| 719 } | 717 } |
| 720 | 718 |
| 721 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, | 719 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, |
| 722 SpdyHeaderBlock* headers) const { | 720 SpdyHeaderBlock* headers) const { |
| 723 if (is_spdy2()) { | 721 std::string scheme, host, path; |
| 724 (*headers)["url"] = url.as_string(); | 722 ParseUrl(url, &scheme, &host, &path); |
| 725 } else { | 723 (*headers)[GetSchemeKey()] = scheme; |
| 726 std::string scheme, host, path; | 724 (*headers)[GetHostKey()] = host; |
| 727 ParseUrl(url, &scheme, &host, &path); | 725 (*headers)[GetPathKey()] = path; |
| 728 (*headers)[GetSchemeKey()] = scheme; | |
| 729 (*headers)[GetHostKey()] = host; | |
| 730 (*headers)[GetPathKey()] = path; | |
| 731 } | |
| 732 } | 726 } |
| 733 | 727 |
| 734 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( | 728 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( |
| 735 base::StringPiece url) const { | 729 base::StringPiece url) const { |
| 736 return ConstructHeaderBlock("GET", url, NULL); | 730 return ConstructHeaderBlock("GET", url, NULL); |
| 737 } | 731 } |
| 738 | 732 |
| 739 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( | 733 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( |
| 740 base::StringPiece url) const { | 734 base::StringPiece url) const { |
| 741 scoped_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); | 735 scoped_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); |
| 742 if (is_spdy2()) | |
| 743 (*headers)[GetPathKey()] = url.data(); | |
| 744 return headers.Pass(); | 736 return headers.Pass(); |
| 745 } | 737 } |
| 746 | 738 |
| 747 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( | 739 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( |
| 748 base::StringPiece url, | 740 base::StringPiece url, |
| 749 int64 content_length) const { | 741 int64 content_length) const { |
| 750 return ConstructHeaderBlock("HEAD", url, &content_length); | 742 return ConstructHeaderBlock("HEAD", url, &content_length); |
| 751 } | 743 } |
| 752 | 744 |
| 753 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( | 745 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 } | 948 } |
| 957 | 949 |
| 958 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], | 950 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], |
| 959 int extra_header_count, | 951 int extra_header_count, |
| 960 bool compressed, | 952 bool compressed, |
| 961 int stream_id, | 953 int stream_id, |
| 962 RequestPriority request_priority, | 954 RequestPriority request_priority, |
| 963 bool direct) const { | 955 bool direct) const { |
| 964 SpdyHeaderBlock block; | 956 SpdyHeaderBlock block; |
| 965 block[GetMethodKey()] = "GET"; | 957 block[GetMethodKey()] = "GET"; |
| 966 block[GetPathKey()] = | 958 block[GetPathKey()] = "/"; |
| 967 (is_spdy2() && !direct) ? "http://www.google.com/" : "/"; | |
| 968 block[GetHostKey()] = "www.google.com"; | 959 block[GetHostKey()] = "www.google.com"; |
| 969 block[GetSchemeKey()] = "http"; | 960 block[GetSchemeKey()] = "http"; |
| 970 MaybeAddVersionHeader(&block); | 961 MaybeAddVersionHeader(&block); |
| 971 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 962 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
| 972 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true); | 963 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true); |
| 973 } | 964 } |
| 974 | 965 |
| 975 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( | 966 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( |
| 976 const char* const extra_headers[], | 967 const char* const extra_headers[], |
| 977 int extra_header_count, | 968 int extra_header_count, |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 return kHeader; | 1243 return kHeader; |
| 1253 } | 1244 } |
| 1254 | 1245 |
| 1255 scoped_ptr<SpdyFramer> SpdyTestUtil::CreateFramer(bool compressed) const { | 1246 scoped_ptr<SpdyFramer> SpdyTestUtil::CreateFramer(bool compressed) const { |
| 1256 scoped_ptr<SpdyFramer> framer(new SpdyFramer(spdy_version_)); | 1247 scoped_ptr<SpdyFramer> framer(new SpdyFramer(spdy_version_)); |
| 1257 framer->set_enable_compression(compressed); | 1248 framer->set_enable_compression(compressed); |
| 1258 return framer.Pass(); | 1249 return framer.Pass(); |
| 1259 } | 1250 } |
| 1260 | 1251 |
| 1261 const char* SpdyTestUtil::GetMethodKey() const { | 1252 const char* SpdyTestUtil::GetMethodKey() const { |
| 1262 return is_spdy2() ? "method" : ":method"; | 1253 return ":method"; |
| 1263 } | 1254 } |
| 1264 | 1255 |
| 1265 const char* SpdyTestUtil::GetStatusKey() const { | 1256 const char* SpdyTestUtil::GetStatusKey() const { |
| 1266 return is_spdy2() ? "status" : ":status"; | 1257 return ":status"; |
| 1267 } | 1258 } |
| 1268 | 1259 |
| 1269 const char* SpdyTestUtil::GetHostKey() const { | 1260 const char* SpdyTestUtil::GetHostKey() const { |
| 1270 if (protocol_ < kProtoSPDY3) | |
| 1271 return "host"; | |
| 1272 if (protocol_ < kProtoSPDY4MinimumVersion) | 1261 if (protocol_ < kProtoSPDY4MinimumVersion) |
| 1273 return ":host"; | 1262 return ":host"; |
| 1274 else | 1263 else |
| 1275 return ":authority"; | 1264 return ":authority"; |
| 1276 } | 1265 } |
| 1277 | 1266 |
| 1278 const char* SpdyTestUtil::GetSchemeKey() const { | 1267 const char* SpdyTestUtil::GetSchemeKey() const { |
| 1279 return is_spdy2() ? "scheme" : ":scheme"; | 1268 return ":scheme"; |
| 1280 } | 1269 } |
| 1281 | 1270 |
| 1282 const char* SpdyTestUtil::GetVersionKey() const { | 1271 const char* SpdyTestUtil::GetVersionKey() const { |
| 1283 return is_spdy2() ? "version" : ":version"; | 1272 return ":version"; |
| 1284 } | 1273 } |
| 1285 | 1274 |
| 1286 const char* SpdyTestUtil::GetPathKey() const { | 1275 const char* SpdyTestUtil::GetPathKey() const { |
| 1287 return is_spdy2() ? "url" : ":path"; | 1276 return ":path"; |
| 1288 } | 1277 } |
| 1289 | 1278 |
| 1290 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( | 1279 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( |
| 1291 base::StringPiece method, | 1280 base::StringPiece method, |
| 1292 base::StringPiece url, | 1281 base::StringPiece url, |
| 1293 int64* content_length) const { | 1282 int64* content_length) const { |
| 1294 std::string scheme, host, path; | 1283 std::string scheme, host, path; |
| 1295 ParseUrl(url.data(), &scheme, &host, &path); | 1284 ParseUrl(url.data(), &scheme, &host, &path); |
| 1296 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 1285 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 1297 (*headers)[GetMethodKey()] = method.as_string(); | 1286 (*headers)[GetMethodKey()] = method.as_string(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1321 } | 1310 } |
| 1322 } | 1311 } |
| 1323 | 1312 |
| 1324 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1313 void SpdyTestUtil::SetPriority(RequestPriority priority, |
| 1325 SpdySynStreamIR* ir) const { | 1314 SpdySynStreamIR* ir) const { |
| 1326 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1315 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
| 1327 priority, spdy_version())); | 1316 priority, spdy_version())); |
| 1328 } | 1317 } |
| 1329 | 1318 |
| 1330 } // namespace net | 1319 } // namespace net |
| OLD | NEW |