Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(933)

Side by Side Diff: net/spdy/spdy_test_util_common.cc

Issue 1357953002: Replace the existing SpdyHeaderBlock typedef with a class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add NET_EXPORT to fix compile error on win_chromium_compile_dbg_ng. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_stream_test_util.cc ('k') | net/spdy/spdy_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (!header_len) 133 if (!header_len)
134 continue; 134 continue;
135 this_value = extra_headers[1 + (i * 2)]; 135 this_value = extra_headers[1 + (i * 2)];
136 std::string new_value; 136 std::string new_value;
137 if (headers->find(this_header) != headers->end()) { 137 if (headers->find(this_header) != headers->end()) {
138 // More than one entry in the header. 138 // More than one entry in the header.
139 // Don't add the header again, just the append to the value, 139 // Don't add the header again, just the append to the value,
140 // separated by a NULL character. 140 // separated by a NULL character.
141 141
142 // Adjust the value. 142 // Adjust the value.
143 new_value = (*headers)[this_header]; 143 new_value = (*headers)[this_header].as_string();
144 // Put in a NULL separator. 144 // Put in a NULL separator.
145 new_value.append(1, '\0'); 145 new_value.append(1, '\0');
146 // Append the new value. 146 // Append the new value.
147 new_value += this_value; 147 new_value += this_value;
148 } else { 148 } else {
149 // Not a duplicate, just write the value. 149 // Not a duplicate, just write the value.
150 new_value = this_value; 150 new_value = this_value;
151 } 151 }
152 (*headers)[this_header] = new_value; 152 (*headers)[this_header] = new_value;
153 } 153 }
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 : protocol_(protocol), 724 : protocol_(protocol),
725 spdy_version_(NextProtoToSpdyMajorVersion(protocol)), 725 spdy_version_(NextProtoToSpdyMajorVersion(protocol)),
726 default_url_(GURL(kDefaultURL)) { 726 default_url_(GURL(kDefaultURL)) {
727 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; 727 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol;
728 } 728 }
729 729
730 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, 730 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url,
731 SpdyHeaderBlock* headers) const { 731 SpdyHeaderBlock* headers) const {
732 std::string scheme, host, path; 732 std::string scheme, host, path;
733 ParseUrl(url, &scheme, &host, &path); 733 ParseUrl(url, &scheme, &host, &path);
734 (*headers)[GetHostKey()] = host;
734 (*headers)[GetSchemeKey()] = scheme; 735 (*headers)[GetSchemeKey()] = scheme;
735 (*headers)[GetHostKey()] = host;
736 (*headers)[GetPathKey()] = path; 736 (*headers)[GetPathKey()] = path;
737 } 737 }
738 738
739 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( 739 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock(
740 base::StringPiece url) const { 740 base::StringPiece url) const {
741 return ConstructHeaderBlock("GET", url, NULL); 741 return ConstructHeaderBlock("GET", url, NULL);
742 } 742 }
743 743
744 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( 744 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy(
745 base::StringPiece url) const { 745 base::StringPiece url) const {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 return ConstructSpdyControlFrame( 859 return ConstructSpdyControlFrame(
860 headers.Pass(), compressed, stream_id, 860 headers.Pass(), compressed, stream_id,
861 request_priority, type, flags, associated_stream_id); 861 request_priority, type, flags, associated_stream_id);
862 } 862 }
863 863
864 std::string SpdyTestUtil::ConstructSpdyReplyString( 864 std::string SpdyTestUtil::ConstructSpdyReplyString(
865 const SpdyHeaderBlock& headers) const { 865 const SpdyHeaderBlock& headers) const {
866 std::string reply_string; 866 std::string reply_string;
867 for (SpdyHeaderBlock::const_iterator it = headers.begin(); 867 for (SpdyHeaderBlock::const_iterator it = headers.begin();
868 it != headers.end(); ++it) { 868 it != headers.end(); ++it) {
869 std::string key = it->first; 869 std::string key = it->first.as_string();
870 // Remove leading colon from "special" headers (for SPDY3 and 870 // Remove leading colon from "special" headers (for SPDY3 and
871 // above). 871 // above).
872 if (spdy_version() >= SPDY3 && key[0] == ':') 872 if (spdy_version() >= SPDY3 && key[0] == ':')
873 key = key.substr(1); 873 key = key.substr(1);
874 for (const std::string& value : 874 for (const std::string& value :
875 base::SplitString(it->second, base::StringPiece("\0", 1), 875 base::SplitString(it->second, base::StringPiece("\0", 1),
876 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 876 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
877 reply_string += key + ": " + value + "\n"; 877 reply_string += key + ": " + value + "\n";
878 } 878 }
879 } 879 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 stream_id, *block, request_priority, compressed, true); 957 stream_id, *block, request_priority, compressed, true);
958 } 958 }
959 959
960 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], 960 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[],
961 int extra_header_count, 961 int extra_header_count,
962 bool compressed, 962 bool compressed,
963 int stream_id, 963 int stream_id,
964 RequestPriority request_priority, 964 RequestPriority request_priority,
965 bool direct) const { 965 bool direct) const {
966 SpdyHeaderBlock block; 966 SpdyHeaderBlock block;
967 MaybeAddVersionHeader(&block);
968 block[GetMethodKey()] = "GET";
967 AddUrlToHeaderBlock(default_url_.spec(), &block); 969 AddUrlToHeaderBlock(default_url_.spec(), &block);
968 block[GetMethodKey()] = "GET";
969 MaybeAddVersionHeader(&block);
970 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 970 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
971 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true); 971 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true);
972 } 972 }
973 973
974 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( 974 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect(
975 const char* const extra_headers[], 975 const char* const extra_headers[],
976 int extra_header_count, 976 int extra_header_count,
977 int stream_id, 977 int stream_id,
978 RequestPriority priority, 978 RequestPriority priority,
979 const HostPortPair& host_port_pair) const { 979 const HostPortPair& host_port_pair) const {
980 SpdyHeaderBlock block; 980 SpdyHeaderBlock block;
981 MaybeAddVersionHeader(&block);
981 block[GetMethodKey()] = "CONNECT"; 982 block[GetMethodKey()] = "CONNECT";
982 if (spdy_version() < HTTP2) { 983 if (spdy_version() < HTTP2) {
983 block[GetPathKey()] = host_port_pair.ToString();
984 block[GetHostKey()] = (host_port_pair.port() == 443) 984 block[GetHostKey()] = (host_port_pair.port() == 443)
985 ? host_port_pair.host() 985 ? host_port_pair.host()
986 : host_port_pair.ToString(); 986 : host_port_pair.ToString();
987 block[GetPathKey()] = host_port_pair.ToString();
987 } else { 988 } else {
988 block[GetHostKey()] = host_port_pair.ToString(); 989 block[GetHostKey()] = host_port_pair.ToString();
989 } 990 }
990
991 MaybeAddVersionHeader(&block);
992 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 991 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
993 return ConstructSpdySyn(stream_id, block, priority, false, false); 992 return ConstructSpdySyn(stream_id, block, priority, false, false);
994 } 993 }
995 994
996 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], 995 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[],
997 int extra_header_count, 996 int extra_header_count,
998 int stream_id, 997 int stream_id,
999 int associated_stream_id, 998 int associated_stream_id,
1000 const char* url) { 999 const char* url) {
1001 if (spdy_version() < HTTP2) { 1000 if (spdy_version() < HTTP2) {
1002 SpdySynStreamIR syn_stream(stream_id); 1001 SpdySynStreamIR syn_stream(stream_id);
1003 syn_stream.set_associated_to_stream_id(associated_stream_id); 1002 syn_stream.set_associated_to_stream_id(associated_stream_id);
1004 syn_stream.SetHeader("hello", "bye"); 1003 syn_stream.SetHeader("hello", "bye");
1005 syn_stream.SetHeader(GetStatusKey(), "200 OK"); 1004 syn_stream.SetHeader(GetStatusKey(), "200 OK");
1006 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); 1005 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1");
1007 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); 1006 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block());
1008 AppendToHeaderBlock(extra_headers, extra_header_count, 1007 AppendToHeaderBlock(extra_headers, extra_header_count,
1009 syn_stream.mutable_header_block()); 1008 syn_stream.mutable_header_block());
1010 return CreateFramer(false)->SerializeFrame(syn_stream); 1009 return CreateFramer(false)->SerializeFrame(syn_stream);
1011 } else { 1010 } else {
1012 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); 1011 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id);
1013 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); 1012 AddUrlToHeaderBlock(url, push_promise.mutable_header_block());
1014 scoped_ptr<SpdyFrame> push_promise_frame( 1013 scoped_ptr<SpdyFrame> push_promise_frame(
1015 CreateFramer(false)->SerializeFrame(push_promise)); 1014 CreateFramer(false)->SerializeFrame(push_promise));
1016 1015
1017 SpdyHeadersIR headers(stream_id); 1016 SpdyHeadersIR headers(stream_id);
1017 headers.SetHeader(GetStatusKey(), "200 OK");
1018 headers.SetHeader("hello", "bye"); 1018 headers.SetHeader("hello", "bye");
1019 headers.SetHeader(GetStatusKey(), "200 OK");
1020 AppendToHeaderBlock(extra_headers, extra_header_count, 1019 AppendToHeaderBlock(extra_headers, extra_header_count,
1021 headers.mutable_header_block()); 1020 headers.mutable_header_block());
1022 scoped_ptr<SpdyFrame> headers_frame( 1021 scoped_ptr<SpdyFrame> headers_frame(
1023 CreateFramer(false)->SerializeFrame(headers)); 1022 CreateFramer(false)->SerializeFrame(headers));
1024 1023
1025 int joint_data_size = push_promise_frame->size() + headers_frame->size(); 1024 int joint_data_size = push_promise_frame->size() + headers_frame->size();
1026 scoped_ptr<char[]> data(new char[joint_data_size]); 1025 scoped_ptr<char[]> data(new char[joint_data_size]);
1027 const SpdyFrame* frames[2] = { 1026 const SpdyFrame* frames[2] = {
1028 push_promise_frame.get(), headers_frame.get(), 1027 push_promise_frame.get(), headers_frame.get(),
1029 }; 1028 };
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 return CreateFramer(false)->SerializeFrame(reply); 1151 return CreateFramer(false)->SerializeFrame(reply);
1153 } 1152 }
1154 } 1153 }
1155 1154
1156 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError( 1155 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError(
1157 const char* const status, 1156 const char* const status,
1158 const char* const* const extra_headers, 1157 const char* const* const extra_headers,
1159 int extra_header_count, 1158 int extra_header_count,
1160 int stream_id) { 1159 int stream_id) {
1161 SpdyHeaderBlock block; 1160 SpdyHeaderBlock block;
1162 block["hello"] = "bye";
1163 block[GetStatusKey()] = status; 1161 block[GetStatusKey()] = status;
1164 MaybeAddVersionHeader(&block); 1162 MaybeAddVersionHeader(&block);
1163 block["hello"] = "bye";
1165 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1164 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1166 1165
1167 return ConstructSpdyReply(stream_id, block); 1166 return ConstructSpdyReply(stream_id, block);
1168 } 1167 }
1169 1168
1170 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(int stream_id) { 1169 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(int stream_id) {
1171 static const char* const kExtraHeaders[] = { 1170 static const char* const kExtraHeaders[] = {
1172 "location", "http://www.foo.com/index.php", 1171 "location", "http://www.foo.com/index.php",
1173 }; 1172 };
1174 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, 1173 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders,
1175 arraysize(kExtraHeaders)/2, stream_id); 1174 arraysize(kExtraHeaders)/2, stream_id);
1176 } 1175 }
1177 1176
1178 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { 1177 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) {
1179 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); 1178 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1);
1180 } 1179 }
1181 1180
1182 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReply( 1181 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReply(
1183 const char* const extra_headers[], 1182 const char* const extra_headers[],
1184 int extra_header_count, 1183 int extra_header_count,
1185 int stream_id) { 1184 int stream_id) {
1186 SpdyHeaderBlock block; 1185 SpdyHeaderBlock block;
1187 block["hello"] = "bye";
1188 block[GetStatusKey()] = "200"; 1186 block[GetStatusKey()] = "200";
1189 MaybeAddVersionHeader(&block); 1187 MaybeAddVersionHeader(&block);
1188 block["hello"] = "bye";
1190 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1189 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1191 1190
1192 return ConstructSpdyReply(stream_id, block); 1191 return ConstructSpdyReply(stream_id, block);
1193 } 1192 }
1194 1193
1195 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, 1194 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url,
1196 SpdyStreamId stream_id, 1195 SpdyStreamId stream_id,
1197 int64 content_length, 1196 int64 content_length,
1198 RequestPriority priority, 1197 RequestPriority priority,
1199 const char* const extra_headers[], 1198 const char* const extra_headers[],
1200 int extra_header_count) { 1199 int extra_header_count) {
1201 scoped_ptr<SpdyHeaderBlock> block( 1200 scoped_ptr<SpdyHeaderBlock> block(
1202 ConstructPostHeaderBlock(url, content_length)); 1201 ConstructPostHeaderBlock(url, content_length));
1203 AppendToHeaderBlock(extra_headers, extra_header_count, block.get()); 1202 AppendToHeaderBlock(extra_headers, extra_header_count, block.get());
1204 return ConstructSpdySyn(stream_id, *block, priority, false, false); 1203 return ConstructSpdySyn(stream_id, *block, priority, false, false);
1205 } 1204 }
1206 1205
1207 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( 1206 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost(
1208 const char* const extra_headers[], 1207 const char* const extra_headers[],
1209 int extra_header_count) { 1208 int extra_header_count) {
1210 SpdyHeaderBlock block; 1209 SpdyHeaderBlock block;
1210 MaybeAddVersionHeader(&block);
1211 block[GetMethodKey()] = "POST"; 1211 block[GetMethodKey()] = "POST";
1212 AddUrlToHeaderBlock(default_url_.spec(), &block); 1212 AddUrlToHeaderBlock(default_url_.spec(), &block);
1213 MaybeAddVersionHeader(&block);
1214 AppendToHeaderBlock(extra_headers, extra_header_count, &block); 1213 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1215 return ConstructSpdySyn(1, block, LOWEST, false, false); 1214 return ConstructSpdySyn(1, block, LOWEST, false, false);
1216 } 1215 }
1217 1216
1218 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply( 1217 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply(
1219 const char* const extra_headers[], 1218 const char* const extra_headers[],
1220 int extra_header_count) { 1219 int extra_header_count) {
1221 // TODO(jgraettinger): Remove this method. 1220 // TODO(jgraettinger): Remove this method.
1222 return ConstructSpdyGetSynReply(NULL, 0, 1); 1221 return ConstructSpdyGetSynReply(NULL, 0, 1);
1223 } 1222 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 return ":path"; 1308 return ":path";
1310 } 1309 }
1311 1310
1312 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock( 1311 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeaderBlock(
1313 base::StringPiece method, 1312 base::StringPiece method,
1314 base::StringPiece url, 1313 base::StringPiece url,
1315 int64* content_length) const { 1314 int64* content_length) const {
1316 std::string scheme, host, path; 1315 std::string scheme, host, path;
1317 ParseUrl(url.data(), &scheme, &host, &path); 1316 ParseUrl(url.data(), &scheme, &host, &path);
1318 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); 1317 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock());
1319 (*headers)[GetMethodKey()] = method.as_string();
1320 (*headers)[GetPathKey()] = path.c_str();
1321 (*headers)[GetHostKey()] = host.c_str();
1322 (*headers)[GetSchemeKey()] = scheme.c_str();
1323 if (include_version_header()) { 1318 if (include_version_header()) {
1324 (*headers)[GetVersionKey()] = "HTTP/1.1"; 1319 (*headers)[GetVersionKey()] = "HTTP/1.1";
1325 } 1320 }
1321 (*headers)[GetMethodKey()] = method.as_string();
1322 (*headers)[GetHostKey()] = host.c_str();
1323 (*headers)[GetSchemeKey()] = scheme.c_str();
1324 (*headers)[GetPathKey()] = path.c_str();
1326 if (content_length) { 1325 if (content_length) {
1327 std::string length_str = base::Int64ToString(*content_length); 1326 std::string length_str = base::Int64ToString(*content_length);
1328 (*headers)["content-length"] = length_str; 1327 (*headers)["content-length"] = length_str;
1329 } 1328 }
1330 return headers.Pass(); 1329 return headers.Pass();
1331 } 1330 }
1332 1331
1333 void SpdyTestUtil::MaybeAddVersionHeader( 1332 void SpdyTestUtil::MaybeAddVersionHeader(
1334 SpdyFrameWithHeaderBlockIR* frame_ir) const { 1333 SpdyFrameWithHeaderBlockIR* frame_ir) const {
1335 if (include_version_header()) { 1334 if (include_version_header()) {
1336 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); 1335 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1");
1337 } 1336 }
1338 } 1337 }
1339 1338
1340 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { 1339 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const {
1341 if (include_version_header()) { 1340 if (include_version_header()) {
1342 (*block)[GetVersionKey()] = "HTTP/1.1"; 1341 (*block)[GetVersionKey()] = "HTTP/1.1";
1343 } 1342 }
1344 } 1343 }
1345 1344
1346 void SpdyTestUtil::SetPriority(RequestPriority priority, 1345 void SpdyTestUtil::SetPriority(RequestPriority priority,
1347 SpdySynStreamIR* ir) const { 1346 SpdySynStreamIR* ir) const {
1348 ir->set_priority(ConvertRequestPriorityToSpdyPriority( 1347 ir->set_priority(ConvertRequestPriorityToSpdyPriority(
1349 priority, spdy_version())); 1348 priority, spdy_version()));
1350 } 1349 }
1351 1350
1352 } // namespace net 1351 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream_test_util.cc ('k') | net/spdy/spdy_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698