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