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

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

Issue 357513003: Stop using SpdySynStreamIR for SPDY 4. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WebSocket test fix. Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | net/spdy/spdy_websocket_test_util.cc » ('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 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 SpdyRstStreamStatus status) const { 932 SpdyRstStreamStatus status) const {
933 SpdyRstStreamIR rst_ir(stream_id, status, ""); 933 SpdyRstStreamIR rst_ir(stream_id, status, "");
934 return CreateFramer(false)->SerializeRstStream(rst_ir); 934 return CreateFramer(false)->SerializeRstStream(rst_ir);
935 } 935 }
936 936
937 SpdyFrame* SpdyTestUtil::ConstructSpdyGet( 937 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(
938 const char* const url, 938 const char* const url,
939 bool compressed, 939 bool compressed,
940 SpdyStreamId stream_id, 940 SpdyStreamId stream_id,
941 RequestPriority request_priority) const { 941 RequestPriority request_priority) const {
942 const SpdyHeaderInfo header_info = { 942 scoped_ptr<SpdyHeaderBlock> block(ConstructGetHeaderBlock(url));
943 SYN_STREAM, 943 return ConstructSpdySyn(
944 stream_id, 944 stream_id, *block, request_priority, compressed, true);
945 0, // associated stream ID
946 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_),
947 0, // credential slot
948 CONTROL_FLAG_FIN,
949 compressed,
950 RST_STREAM_INVALID, // status
951 NULL, // data
952 0, // length
953 DATA_FLAG_NONE
954 };
955 return ConstructSpdyFrame(header_info, ConstructGetHeaderBlock(url));
956 } 945 }
957 946
958 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], 947 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[],
959 int extra_header_count, 948 int extra_header_count,
960 bool compressed, 949 bool compressed,
961 int stream_id, 950 int stream_id,
962 RequestPriority request_priority, 951 RequestPriority request_priority,
963 bool direct) const { 952 bool direct) const {
964 SpdySynStreamIR syn_stream(stream_id); 953 SpdyHeaderBlock block;
965 syn_stream.set_priority( 954 block[GetMethodKey()] = "GET";
966 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_)); 955 block[GetPathKey()] =
967 syn_stream.set_fin(true); 956 (is_spdy2() && !direct) ? "http://www.google.com/" : "/";
968 syn_stream.SetHeader(GetMethodKey(), "GET"); 957 block[GetHostKey()] = "www.google.com";
969 syn_stream.SetHeader(GetHostKey(), "www.google.com"); 958 block[GetSchemeKey()] = "http";
970 syn_stream.SetHeader(GetSchemeKey(), "http"); 959 MaybeAddVersionHeader(&block);
971 syn_stream.SetHeader(GetPathKey(), (is_spdy2() && !direct) ? 960 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
972 "http://www.google.com/" : "/"); 961 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true);
973 MaybeAddVersionHeader(&syn_stream);
974 AppendToHeaderBlock(extra_headers, extra_header_count,
975 syn_stream.mutable_name_value_block());
976 return CreateFramer(compressed)->SerializeFrame(syn_stream);
977 } 962 }
978 963
979 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( 964 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect(
980 const char* const extra_headers[], 965 const char* const extra_headers[],
981 int extra_header_count, 966 int extra_header_count,
982 int stream_id, 967 int stream_id,
983 RequestPriority priority) const { 968 RequestPriority priority) const {
984 SpdySynStreamIR syn_stream(stream_id); 969 SpdyHeaderBlock block;
985 syn_stream.set_priority( 970 block[GetMethodKey()] = "CONNECT";
986 ConvertRequestPriorityToSpdyPriority(priority, spdy_version_)); 971 block[GetPathKey()] = "www.google.com:443";
987 syn_stream.SetHeader(GetMethodKey(), "CONNECT"); 972 block[GetHostKey()] = "www.google.com";
988 syn_stream.SetHeader(GetPathKey(), "www.google.com:443"); 973 MaybeAddVersionHeader(&block);
989 syn_stream.SetHeader(GetHostKey(), "www.google.com"); 974 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
990 MaybeAddVersionHeader(&syn_stream); 975 return ConstructSpdySyn(stream_id, block, priority, false, false);
991 AppendToHeaderBlock(extra_headers, extra_header_count,
992 syn_stream.mutable_name_value_block());
993 return CreateFramer(false)->SerializeFrame(syn_stream);
994 } 976 }
995 977
996 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], 978 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[],
997 int extra_header_count, 979 int extra_header_count,
998 int stream_id, 980 int stream_id,
999 int associated_stream_id, 981 int associated_stream_id,
1000 const char* url) { 982 const char* url) {
1001 if (spdy_version() < SPDY4) { 983 if (spdy_version() < SPDY4) {
1002 SpdySynStreamIR syn_stream(stream_id); 984 SpdySynStreamIR syn_stream(stream_id);
1003 syn_stream.set_associated_to_stream_id(associated_stream_id); 985 syn_stream.set_associated_to_stream_id(associated_stream_id);
1004 syn_stream.SetHeader("hello", "bye"); 986 syn_stream.SetHeader("hello", "bye");
1005 syn_stream.SetHeader(GetStatusKey(), "200 OK"); 987 syn_stream.SetHeader(GetStatusKey(), "200 OK");
1006 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); 988 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1");
1007 AddUrlToHeaderBlock(url, syn_stream.mutable_name_value_block()); 989 AddUrlToHeaderBlock(url, syn_stream.mutable_name_value_block());
1008 AppendToHeaderBlock(extra_headers, 990 AppendToHeaderBlock(extra_headers,
1009 extra_header_count, 991 extra_header_count,
1010 syn_stream.mutable_name_value_block()); 992 syn_stream.mutable_name_value_block());
1011 return CreateFramer(false)->SerializeFrame(syn_stream); 993 return CreateFramer(false)->SerializeFrame(syn_stream);
1012 } else { 994 } else {
1013 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); 995 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id);
1014 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block()); 996 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block());
1015 scoped_ptr<SpdyFrame> push_promise_frame( 997 scoped_ptr<SpdyFrame> push_promise_frame(
1016 CreateFramer(false)->SerializeFrame(push_promise)); 998 CreateFramer(false)->SerializeFrame(push_promise));
1017 999
1018 // Use SynStreamIR to create HEADERS+PRIORITY. Direct creation breaks 1000 SpdyHeadersIR headers(stream_id);
1019 // framer.
1020 SpdySynStreamIR headers(stream_id);
1021 SetPriority(LOWEST, &headers);
1022 headers.SetHeader("hello", "bye"); 1001 headers.SetHeader("hello", "bye");
1023 headers.SetHeader(GetStatusKey(), "200 OK"); 1002 headers.SetHeader(GetStatusKey(), "200 OK");
1024 AppendToHeaderBlock( 1003 AppendToHeaderBlock(
1025 extra_headers, extra_header_count, headers.mutable_name_value_block()); 1004 extra_headers, extra_header_count, headers.mutable_name_value_block());
1026 scoped_ptr<SpdyFrame> headers_frame( 1005 scoped_ptr<SpdyFrame> headers_frame(
1027 CreateFramer(false)->SerializeFrame(headers)); 1006 CreateFramer(false)->SerializeFrame(headers));
1028 1007
1029 int joint_data_size = push_promise_frame->size() + headers_frame->size(); 1008 int joint_data_size = push_promise_frame->size() + headers_frame->size();
1030 scoped_ptr<char[]> data(new char[joint_data_size]); 1009 scoped_ptr<char[]> data(new char[joint_data_size]);
1031 const SpdyFrame* frames[2] = { 1010 const SpdyFrame* frames[2] = {
(...skipping 24 matching lines...) Expand all
1056 AppendToHeaderBlock(extra_headers, 1035 AppendToHeaderBlock(extra_headers,
1057 extra_header_count, 1036 extra_header_count,
1058 syn_stream.mutable_name_value_block()); 1037 syn_stream.mutable_name_value_block());
1059 return CreateFramer(false)->SerializeFrame(syn_stream); 1038 return CreateFramer(false)->SerializeFrame(syn_stream);
1060 } else { 1039 } else {
1061 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); 1040 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id);
1062 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block()); 1041 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block());
1063 scoped_ptr<SpdyFrame> push_promise_frame( 1042 scoped_ptr<SpdyFrame> push_promise_frame(
1064 CreateFramer(false)->SerializeFrame(push_promise)); 1043 CreateFramer(false)->SerializeFrame(push_promise));
1065 1044
1066 // Use SynStreamIR to create HEADERS+PRIORITY. Direct creation breaks 1045 SpdyHeadersIR headers(stream_id);
1067 // framer.
1068 SpdySynStreamIR headers(stream_id);
1069 SetPriority(LOWEST, &headers);
1070 headers.SetHeader("hello", "bye"); 1046 headers.SetHeader("hello", "bye");
1071 headers.SetHeader(GetStatusKey(), status); 1047 headers.SetHeader(GetStatusKey(), status);
1072 headers.SetHeader("location", location); 1048 headers.SetHeader("location", location);
1073 AppendToHeaderBlock( 1049 AppendToHeaderBlock(
1074 extra_headers, extra_header_count, headers.mutable_name_value_block()); 1050 extra_headers, extra_header_count, headers.mutable_name_value_block());
1075 scoped_ptr<SpdyFrame> headers_frame( 1051 scoped_ptr<SpdyFrame> headers_frame(
1076 CreateFramer(false)->SerializeFrame(headers)); 1052 CreateFramer(false)->SerializeFrame(headers));
1077 1053
1078 int joint_data_size = push_promise_frame->size() + headers_frame->size(); 1054 int joint_data_size = push_promise_frame->size() + headers_frame->size();
1079 scoped_ptr<char[]> data(new char[joint_data_size]); 1055 scoped_ptr<char[]> data(new char[joint_data_size]);
(...skipping 29 matching lines...) Expand all
1109 const char* const extra_headers[], 1085 const char* const extra_headers[],
1110 int extra_header_count) { 1086 int extra_header_count) {
1111 SpdyHeadersIR headers(stream_id); 1087 SpdyHeadersIR headers(stream_id);
1112 headers.SetHeader(GetStatusKey(), "200 OK"); 1088 headers.SetHeader(GetStatusKey(), "200 OK");
1113 MaybeAddVersionHeader(&headers); 1089 MaybeAddVersionHeader(&headers);
1114 AppendToHeaderBlock(extra_headers, extra_header_count, 1090 AppendToHeaderBlock(extra_headers, extra_header_count,
1115 headers.mutable_name_value_block()); 1091 headers.mutable_name_value_block());
1116 return CreateFramer(false)->SerializeFrame(headers); 1092 return CreateFramer(false)->SerializeFrame(headers);
1117 } 1093 }
1118 1094
1095 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id,
1096 const SpdyHeaderBlock& block,
1097 RequestPriority priority,
1098 bool compressed,
1099 bool fin) const {
1100 if (protocol_ < kProtoSPDY4) {
1101 SpdySynStreamIR syn_stream(stream_id);
1102 syn_stream.set_name_value_block(block);
1103 syn_stream.set_priority(
1104 ConvertRequestPriorityToSpdyPriority(priority, spdy_version()));
1105 syn_stream.set_fin(fin);
1106 return CreateFramer(compressed)->SerializeFrame(syn_stream);
1107 } else {
1108 SpdyHeadersIR headers(stream_id);
1109 headers.set_name_value_block(block);
1110 headers.set_has_priority(true);
1111 headers.set_priority(
1112 ConvertRequestPriorityToSpdyPriority(priority, spdy_version()));
1113 headers.set_fin(fin);
1114 return CreateFramer(compressed)->SerializeFrame(headers);
1115 }
1116 }
1117
1119 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, 1118 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id,
1120 const SpdyHeaderBlock& headers) { 1119 const SpdyHeaderBlock& headers) {
1121 if (protocol_ < kProtoSPDY4) { 1120 if (protocol_ < kProtoSPDY4) {
1122 SpdySynReplyIR syn_reply(stream_id); 1121 SpdySynReplyIR syn_reply(stream_id);
1123 syn_reply.set_name_value_block(headers); 1122 syn_reply.set_name_value_block(headers);
1124 return CreateFramer(false)->SerializeFrame(syn_reply); 1123 return CreateFramer(false)->SerializeFrame(syn_reply);
1125 } else { 1124 } else {
1126 SpdyHeadersIR reply(stream_id); 1125 SpdyHeadersIR reply(stream_id);
1127 reply.set_name_value_block(headers); 1126 reply.set_name_value_block(headers);
1128 return CreateFramer(false)->SerializeFrame(reply); 1127 return CreateFramer(false)->SerializeFrame(reply);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 1166
1168 return ConstructSpdyReply(stream_id, block); 1167 return ConstructSpdyReply(stream_id, block);
1169 } 1168 }
1170 1169
1171 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, 1170 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url,
1172 SpdyStreamId stream_id, 1171 SpdyStreamId stream_id,
1173 int64 content_length, 1172 int64 content_length,
1174 RequestPriority priority, 1173 RequestPriority priority,
1175 const char* const extra_headers[], 1174 const char* const extra_headers[],
1176 int extra_header_count) { 1175 int extra_header_count) {
1177 const SpdyHeaderInfo kSynStartHeader = { 1176 scoped_ptr<SpdyHeaderBlock> block(
1178 SYN_STREAM, 1177 ConstructPostHeaderBlock(url, content_length));
1179 stream_id, 1178 AppendToHeaderBlock(extra_headers, extra_header_count, block.get());
1180 0, // Associated stream ID 1179 return ConstructSpdySyn(stream_id, *block, priority, false, false);
1181 ConvertRequestPriorityToSpdyPriority(priority, spdy_version_),
1182 kSpdyCredentialSlotUnused,
1183 CONTROL_FLAG_NONE,
1184 false, // Compressed
1185 RST_STREAM_INVALID,
1186 NULL, // Data
1187 0, // Length
1188 DATA_FLAG_NONE
1189 };
1190 return ConstructSpdyFrame(
1191 kSynStartHeader, ConstructPostHeaderBlock(url, content_length));
1192 } 1180 }
1193 1181
1194 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( 1182 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost(
1195 const char* const extra_headers[], 1183 const char* const extra_headers[],
1196 int extra_header_count) { 1184 int extra_header_count) {
1197 SpdySynStreamIR syn_stream(1); 1185 SpdyHeaderBlock block;
1198 syn_stream.SetHeader(GetMethodKey(), "POST"); 1186 block[GetMethodKey()] = "POST";
1199 syn_stream.SetHeader(GetPathKey(), "/"); 1187 block[GetPathKey()] = "/";
1200 syn_stream.SetHeader(GetHostKey(), "www.google.com"); 1188 block[GetHostKey()] = "www.google.com";
1201 syn_stream.SetHeader(GetSchemeKey(), "http"); 1189 block[GetSchemeKey()] = "http";
1202 MaybeAddVersionHeader(&syn_stream); 1190 MaybeAddVersionHeader(&block);
1203 SetPriority(LOWEST, &syn_stream); 1191 AppendToHeaderBlock(extra_headers, extra_header_count, &block);
1204 AppendToHeaderBlock(extra_headers, extra_header_count, 1192 return ConstructSpdySyn(1, block, LOWEST, false, false);
1205 syn_stream.mutable_name_value_block());
1206 return CreateFramer(false)->SerializeFrame(syn_stream);
1207 } 1193 }
1208 1194
1209 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply( 1195 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply(
1210 const char* const extra_headers[], 1196 const char* const extra_headers[],
1211 int extra_header_count) { 1197 int extra_header_count) {
1212 // TODO(jgraettinger): Remove this method. 1198 // TODO(jgraettinger): Remove this method.
1213 return ConstructSpdyGetSynReply(NULL, 0, 1); 1199 return ConstructSpdyGetSynReply(NULL, 0, 1);
1214 } 1200 }
1215 1201
1216 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) { 1202 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 } 1310 }
1325 } 1311 }
1326 1312
1327 void SpdyTestUtil::SetPriority(RequestPriority priority, 1313 void SpdyTestUtil::SetPriority(RequestPriority priority,
1328 SpdySynStreamIR* ir) const { 1314 SpdySynStreamIR* ir) const {
1329 ir->set_priority(ConvertRequestPriorityToSpdyPriority( 1315 ir->set_priority(ConvertRequestPriorityToSpdyPriority(
1330 priority, spdy_version())); 1316 priority, spdy_version()));
1331 } 1317 }
1332 1318
1333 } // namespace net 1319 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_test_util_common.h ('k') | net/spdy/spdy_websocket_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698