| 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 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 int extra_header_count, | 994 int extra_header_count, |
| 995 int stream_id, | 995 int stream_id, |
| 996 int associated_stream_id, | 996 int associated_stream_id, |
| 997 const char* url) { | 997 const char* url) { |
| 998 if (spdy_version() < HTTP2) { | 998 if (spdy_version() < HTTP2) { |
| 999 SpdySynStreamIR syn_stream(stream_id); | 999 SpdySynStreamIR syn_stream(stream_id); |
| 1000 syn_stream.set_associated_to_stream_id(associated_stream_id); | 1000 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 1001 syn_stream.SetHeader("hello", "bye"); | 1001 syn_stream.SetHeader("hello", "bye"); |
| 1002 syn_stream.SetHeader(GetStatusKey(), "200 OK"); | 1002 syn_stream.SetHeader(GetStatusKey(), "200 OK"); |
| 1003 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); | 1003 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 1004 AddUrlToHeaderBlock(url, syn_stream.mutable_name_value_block()); | 1004 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); |
| 1005 AppendToHeaderBlock(extra_headers, | 1005 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 1006 extra_header_count, | 1006 syn_stream.mutable_header_block()); |
| 1007 syn_stream.mutable_name_value_block()); | |
| 1008 return CreateFramer(false)->SerializeFrame(syn_stream); | 1007 return CreateFramer(false)->SerializeFrame(syn_stream); |
| 1009 } else { | 1008 } else { |
| 1010 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 1009 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1011 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block()); | 1010 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); |
| 1012 scoped_ptr<SpdyFrame> push_promise_frame( | 1011 scoped_ptr<SpdyFrame> push_promise_frame( |
| 1013 CreateFramer(false)->SerializeFrame(push_promise)); | 1012 CreateFramer(false)->SerializeFrame(push_promise)); |
| 1014 | 1013 |
| 1015 SpdyHeadersIR headers(stream_id); | 1014 SpdyHeadersIR headers(stream_id); |
| 1016 headers.SetHeader("hello", "bye"); | 1015 headers.SetHeader("hello", "bye"); |
| 1017 headers.SetHeader(GetStatusKey(), "200 OK"); | 1016 headers.SetHeader(GetStatusKey(), "200 OK"); |
| 1018 AppendToHeaderBlock( | 1017 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 1019 extra_headers, extra_header_count, headers.mutable_name_value_block()); | 1018 headers.mutable_header_block()); |
| 1020 scoped_ptr<SpdyFrame> headers_frame( | 1019 scoped_ptr<SpdyFrame> headers_frame( |
| 1021 CreateFramer(false)->SerializeFrame(headers)); | 1020 CreateFramer(false)->SerializeFrame(headers)); |
| 1022 | 1021 |
| 1023 int joint_data_size = push_promise_frame->size() + headers_frame->size(); | 1022 int joint_data_size = push_promise_frame->size() + headers_frame->size(); |
| 1024 scoped_ptr<char[]> data(new char[joint_data_size]); | 1023 scoped_ptr<char[]> data(new char[joint_data_size]); |
| 1025 const SpdyFrame* frames[2] = { | 1024 const SpdyFrame* frames[2] = { |
| 1026 push_promise_frame.get(), headers_frame.get(), | 1025 push_promise_frame.get(), headers_frame.get(), |
| 1027 }; | 1026 }; |
| 1028 int combined_size = | 1027 int combined_size = |
| 1029 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); | 1028 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 1030 DCHECK_EQ(combined_size, joint_data_size); | 1029 DCHECK_EQ(combined_size, joint_data_size); |
| 1031 return new SpdyFrame(data.release(), joint_data_size, true); | 1030 return new SpdyFrame(data.release(), joint_data_size, true); |
| 1032 } | 1031 } |
| 1033 } | 1032 } |
| 1034 | 1033 |
| 1035 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], | 1034 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], |
| 1036 int extra_header_count, | 1035 int extra_header_count, |
| 1037 int stream_id, | 1036 int stream_id, |
| 1038 int associated_stream_id, | 1037 int associated_stream_id, |
| 1039 const char* url, | 1038 const char* url, |
| 1040 const char* status, | 1039 const char* status, |
| 1041 const char* location) { | 1040 const char* location) { |
| 1042 if (spdy_version() < HTTP2) { | 1041 if (spdy_version() < HTTP2) { |
| 1043 SpdySynStreamIR syn_stream(stream_id); | 1042 SpdySynStreamIR syn_stream(stream_id); |
| 1044 syn_stream.set_associated_to_stream_id(associated_stream_id); | 1043 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 1045 syn_stream.SetHeader("hello", "bye"); | 1044 syn_stream.SetHeader("hello", "bye"); |
| 1046 syn_stream.SetHeader(GetStatusKey(), status); | 1045 syn_stream.SetHeader(GetStatusKey(), status); |
| 1047 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); | 1046 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 1048 syn_stream.SetHeader("location", location); | 1047 syn_stream.SetHeader("location", location); |
| 1049 AddUrlToHeaderBlock(url, syn_stream.mutable_name_value_block()); | 1048 AddUrlToHeaderBlock(url, syn_stream.mutable_header_block()); |
| 1050 AppendToHeaderBlock(extra_headers, | 1049 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 1051 extra_header_count, | 1050 syn_stream.mutable_header_block()); |
| 1052 syn_stream.mutable_name_value_block()); | |
| 1053 return CreateFramer(false)->SerializeFrame(syn_stream); | 1051 return CreateFramer(false)->SerializeFrame(syn_stream); |
| 1054 } else { | 1052 } else { |
| 1055 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 1053 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1056 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block()); | 1054 AddUrlToHeaderBlock(url, push_promise.mutable_header_block()); |
| 1057 scoped_ptr<SpdyFrame> push_promise_frame( | 1055 scoped_ptr<SpdyFrame> push_promise_frame( |
| 1058 CreateFramer(false)->SerializeFrame(push_promise)); | 1056 CreateFramer(false)->SerializeFrame(push_promise)); |
| 1059 | 1057 |
| 1060 SpdyHeadersIR headers(stream_id); | 1058 SpdyHeadersIR headers(stream_id); |
| 1061 headers.SetHeader("hello", "bye"); | 1059 headers.SetHeader("hello", "bye"); |
| 1062 headers.SetHeader(GetStatusKey(), status); | 1060 headers.SetHeader(GetStatusKey(), status); |
| 1063 headers.SetHeader("location", location); | 1061 headers.SetHeader("location", location); |
| 1064 AppendToHeaderBlock( | 1062 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 1065 extra_headers, extra_header_count, headers.mutable_name_value_block()); | 1063 headers.mutable_header_block()); |
| 1066 scoped_ptr<SpdyFrame> headers_frame( | 1064 scoped_ptr<SpdyFrame> headers_frame( |
| 1067 CreateFramer(false)->SerializeFrame(headers)); | 1065 CreateFramer(false)->SerializeFrame(headers)); |
| 1068 | 1066 |
| 1069 int joint_data_size = push_promise_frame->size() + headers_frame->size(); | 1067 int joint_data_size = push_promise_frame->size() + headers_frame->size(); |
| 1070 scoped_ptr<char[]> data(new char[joint_data_size]); | 1068 scoped_ptr<char[]> data(new char[joint_data_size]); |
| 1071 const SpdyFrame* frames[2] = { | 1069 const SpdyFrame* frames[2] = { |
| 1072 push_promise_frame.get(), headers_frame.get(), | 1070 push_promise_frame.get(), headers_frame.get(), |
| 1073 }; | 1071 }; |
| 1074 int combined_size = | 1072 int combined_size = |
| 1075 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); | 1073 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 1076 DCHECK_EQ(combined_size, joint_data_size); | 1074 DCHECK_EQ(combined_size, joint_data_size); |
| 1077 return new SpdyFrame(data.release(), joint_data_size, true); | 1075 return new SpdyFrame(data.release(), joint_data_size, true); |
| 1078 } | 1076 } |
| 1079 } | 1077 } |
| 1080 | 1078 |
| 1081 SpdyFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( | 1079 SpdyFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( |
| 1082 scoped_ptr<SpdyHeaderBlock> headers, | 1080 scoped_ptr<SpdyHeaderBlock> headers, |
| 1083 int stream_id, | 1081 int stream_id, |
| 1084 int associated_stream_id) { | 1082 int associated_stream_id) { |
| 1085 if (spdy_version() < HTTP2) { | 1083 if (spdy_version() < HTTP2) { |
| 1086 SpdySynStreamIR syn_stream(stream_id); | 1084 SpdySynStreamIR syn_stream(stream_id); |
| 1087 syn_stream.set_associated_to_stream_id(associated_stream_id); | 1085 syn_stream.set_associated_to_stream_id(associated_stream_id); |
| 1088 SetPriority(LOWEST, &syn_stream); | 1086 SetPriority(LOWEST, &syn_stream); |
| 1089 syn_stream.set_name_value_block(*headers); | 1087 syn_stream.set_header_block(*headers); |
| 1090 return CreateFramer(false)->SerializeFrame(syn_stream); | 1088 return CreateFramer(false)->SerializeFrame(syn_stream); |
| 1091 } else { | 1089 } else { |
| 1092 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); | 1090 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1093 push_promise.set_name_value_block(*headers); | 1091 push_promise.set_header_block(*headers); |
| 1094 return CreateFramer(false)->SerializeFrame(push_promise); | 1092 return CreateFramer(false)->SerializeFrame(push_promise); |
| 1095 } | 1093 } |
| 1096 } | 1094 } |
| 1097 | 1095 |
| 1098 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( | 1096 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( |
| 1099 int stream_id, | 1097 int stream_id, |
| 1100 const char* const extra_headers[], | 1098 const char* const extra_headers[], |
| 1101 int extra_header_count) { | 1099 int extra_header_count) { |
| 1102 SpdyHeadersIR headers(stream_id); | 1100 SpdyHeadersIR headers(stream_id); |
| 1103 headers.SetHeader(GetStatusKey(), "200 OK"); | 1101 headers.SetHeader(GetStatusKey(), "200 OK"); |
| 1104 MaybeAddVersionHeader(&headers); | 1102 MaybeAddVersionHeader(&headers); |
| 1105 AppendToHeaderBlock(extra_headers, extra_header_count, | 1103 AppendToHeaderBlock(extra_headers, extra_header_count, |
| 1106 headers.mutable_name_value_block()); | 1104 headers.mutable_header_block()); |
| 1107 return CreateFramer(false)->SerializeFrame(headers); | 1105 return CreateFramer(false)->SerializeFrame(headers); |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, | 1108 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, |
| 1111 const SpdyHeaderBlock& block, | 1109 const SpdyHeaderBlock& block, |
| 1112 RequestPriority priority, | 1110 RequestPriority priority, |
| 1113 bool compressed, | 1111 bool compressed, |
| 1114 bool fin) const { | 1112 bool fin) const { |
| 1115 if (protocol_ < kProtoHTTP2MinimumVersion) { | 1113 if (protocol_ < kProtoHTTP2MinimumVersion) { |
| 1116 SpdySynStreamIR syn_stream(stream_id); | 1114 SpdySynStreamIR syn_stream(stream_id); |
| 1117 syn_stream.set_name_value_block(block); | 1115 syn_stream.set_header_block(block); |
| 1118 syn_stream.set_priority( | 1116 syn_stream.set_priority( |
| 1119 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1117 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
| 1120 syn_stream.set_fin(fin); | 1118 syn_stream.set_fin(fin); |
| 1121 return CreateFramer(compressed)->SerializeFrame(syn_stream); | 1119 return CreateFramer(compressed)->SerializeFrame(syn_stream); |
| 1122 } else { | 1120 } else { |
| 1123 SpdyHeadersIR headers(stream_id); | 1121 SpdyHeadersIR headers(stream_id); |
| 1124 headers.set_name_value_block(block); | 1122 headers.set_header_block(block); |
| 1125 headers.set_has_priority(true); | 1123 headers.set_has_priority(true); |
| 1126 headers.set_priority( | 1124 headers.set_priority( |
| 1127 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1125 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
| 1128 headers.set_fin(fin); | 1126 headers.set_fin(fin); |
| 1129 return CreateFramer(compressed)->SerializeFrame(headers); | 1127 return CreateFramer(compressed)->SerializeFrame(headers); |
| 1130 } | 1128 } |
| 1131 } | 1129 } |
| 1132 | 1130 |
| 1133 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, | 1131 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, |
| 1134 const SpdyHeaderBlock& headers) { | 1132 const SpdyHeaderBlock& headers) { |
| 1135 if (protocol_ < kProtoHTTP2MinimumVersion) { | 1133 if (protocol_ < kProtoHTTP2MinimumVersion) { |
| 1136 SpdySynReplyIR syn_reply(stream_id); | 1134 SpdySynReplyIR syn_reply(stream_id); |
| 1137 syn_reply.set_name_value_block(headers); | 1135 syn_reply.set_header_block(headers); |
| 1138 return CreateFramer(false)->SerializeFrame(syn_reply); | 1136 return CreateFramer(false)->SerializeFrame(syn_reply); |
| 1139 } else { | 1137 } else { |
| 1140 SpdyHeadersIR reply(stream_id); | 1138 SpdyHeadersIR reply(stream_id); |
| 1141 reply.set_name_value_block(headers); | 1139 reply.set_header_block(headers); |
| 1142 return CreateFramer(false)->SerializeFrame(reply); | 1140 return CreateFramer(false)->SerializeFrame(reply); |
| 1143 } | 1141 } |
| 1144 } | 1142 } |
| 1145 | 1143 |
| 1146 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError( | 1144 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError( |
| 1147 const char* const status, | 1145 const char* const status, |
| 1148 const char* const* const extra_headers, | 1146 const char* const* const extra_headers, |
| 1149 int extra_header_count, | 1147 int extra_header_count, |
| 1150 int stream_id) { | 1148 int stream_id) { |
| 1151 SpdyHeaderBlock block; | 1149 SpdyHeaderBlock block; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 (*headers)[GetVersionKey()] = "HTTP/1.1"; | 1312 (*headers)[GetVersionKey()] = "HTTP/1.1"; |
| 1315 } | 1313 } |
| 1316 if (content_length) { | 1314 if (content_length) { |
| 1317 std::string length_str = base::Int64ToString(*content_length); | 1315 std::string length_str = base::Int64ToString(*content_length); |
| 1318 (*headers)["content-length"] = length_str; | 1316 (*headers)["content-length"] = length_str; |
| 1319 } | 1317 } |
| 1320 return headers.Pass(); | 1318 return headers.Pass(); |
| 1321 } | 1319 } |
| 1322 | 1320 |
| 1323 void SpdyTestUtil::MaybeAddVersionHeader( | 1321 void SpdyTestUtil::MaybeAddVersionHeader( |
| 1324 SpdyFrameWithNameValueBlockIR* frame_ir) const { | 1322 SpdyFrameWithHeaderBlockIR* frame_ir) const { |
| 1325 if (include_version_header()) { | 1323 if (include_version_header()) { |
| 1326 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); | 1324 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 1327 } | 1325 } |
| 1328 } | 1326 } |
| 1329 | 1327 |
| 1330 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { | 1328 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { |
| 1331 if (include_version_header()) { | 1329 if (include_version_header()) { |
| 1332 (*block)[GetVersionKey()] = "HTTP/1.1"; | 1330 (*block)[GetVersionKey()] = "HTTP/1.1"; |
| 1333 } | 1331 } |
| 1334 } | 1332 } |
| 1335 | 1333 |
| 1336 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1334 void SpdyTestUtil::SetPriority(RequestPriority priority, |
| 1337 SpdySynStreamIR* ir) const { | 1335 SpdySynStreamIR* ir) const { |
| 1338 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1336 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
| 1339 priority, spdy_version())); | 1337 priority, spdy_version())); |
| 1340 } | 1338 } |
| 1341 | 1339 |
| 1342 } // namespace net | 1340 } // namespace net |
| OLD | NEW |