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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 AppendToHeaderBlock(extra_headers, extra_header_count, | 991 AppendToHeaderBlock(extra_headers, extra_header_count, |
992 syn_stream.mutable_name_value_block()); | 992 syn_stream.mutable_name_value_block()); |
993 return CreateFramer(false)->SerializeFrame(syn_stream); | 993 return CreateFramer(false)->SerializeFrame(syn_stream); |
994 } | 994 } |
995 | 995 |
996 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], | 996 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], |
997 int extra_header_count, | 997 int extra_header_count, |
998 int stream_id, | 998 int stream_id, |
999 int associated_stream_id, | 999 int associated_stream_id, |
1000 const char* url) { | 1000 const char* url) { |
1001 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 1001 if (spdy_version() < SPDY4) { |
1002 (*headers)["hello"] = "bye"; | 1002 SpdySynStreamIR syn_stream(stream_id); |
1003 (*headers)[GetStatusKey()] = "200 OK"; | 1003 syn_stream.set_associated_to_stream_id(associated_stream_id); |
1004 if (include_version_header()) { | 1004 syn_stream.SetHeader("hello", "bye"); |
1005 (*headers)[GetVersionKey()] = "HTTP/1.1"; | 1005 syn_stream.SetHeader(GetStatusKey(), "200 OK"); |
| 1006 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 1007 AddUrlToHeaderBlock(url, syn_stream.mutable_name_value_block()); |
| 1008 AppendToHeaderBlock(extra_headers, |
| 1009 extra_header_count, |
| 1010 syn_stream.mutable_name_value_block()); |
| 1011 return CreateFramer(false)->SerializeFrame(syn_stream); |
| 1012 } else { |
| 1013 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1014 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block()); |
| 1015 scoped_ptr<SpdyFrame> push_promise_frame( |
| 1016 CreateFramer(false)->SerializeFrame(push_promise)); |
| 1017 |
| 1018 // Use SynStreamIR to create HEADERS+PRIORITY. Direct creation breaks |
| 1019 // framer. |
| 1020 SpdySynStreamIR headers(stream_id); |
| 1021 SetPriority(LOWEST, &headers); |
| 1022 headers.SetHeader("hello", "bye"); |
| 1023 headers.SetHeader(GetStatusKey(), "200 OK"); |
| 1024 AppendToHeaderBlock( |
| 1025 extra_headers, extra_header_count, headers.mutable_name_value_block()); |
| 1026 scoped_ptr<SpdyFrame> headers_frame( |
| 1027 CreateFramer(false)->SerializeFrame(headers)); |
| 1028 |
| 1029 int joint_data_size = push_promise_frame->size() + headers_frame->size(); |
| 1030 scoped_ptr<char[]> data(new char[joint_data_size]); |
| 1031 const SpdyFrame* frames[2] = { |
| 1032 push_promise_frame.get(), headers_frame.get(), |
| 1033 }; |
| 1034 int combined_size = |
| 1035 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 1036 DCHECK_EQ(combined_size, joint_data_size); |
| 1037 return new SpdyFrame(data.release(), joint_data_size, true); |
1006 } | 1038 } |
1007 AddUrlToHeaderBlock(url, headers.get()); | |
1008 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | |
1009 return ConstructSpdyControlFrame(headers.Pass(), | |
1010 false, | |
1011 stream_id, | |
1012 LOWEST, | |
1013 SYN_STREAM, | |
1014 CONTROL_FLAG_NONE, | |
1015 associated_stream_id); | |
1016 } | 1039 } |
1017 | 1040 |
1018 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], | 1041 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], |
1019 int extra_header_count, | 1042 int extra_header_count, |
1020 int stream_id, | 1043 int stream_id, |
1021 int associated_stream_id, | 1044 int associated_stream_id, |
1022 const char* url, | 1045 const char* url, |
1023 const char* status, | 1046 const char* status, |
1024 const char* location) { | 1047 const char* location) { |
1025 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 1048 if (spdy_version() < SPDY4) { |
1026 (*headers)["hello"] = "bye"; | 1049 SpdySynStreamIR syn_stream(stream_id); |
1027 (*headers)[GetStatusKey()] = status; | 1050 syn_stream.set_associated_to_stream_id(associated_stream_id); |
1028 if (include_version_header()) { | 1051 syn_stream.SetHeader("hello", "bye"); |
1029 (*headers)[GetVersionKey()] = "HTTP/1.1"; | 1052 syn_stream.SetHeader(GetStatusKey(), status); |
| 1053 syn_stream.SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 1054 syn_stream.SetHeader("location", location); |
| 1055 AddUrlToHeaderBlock(url, syn_stream.mutable_name_value_block()); |
| 1056 AppendToHeaderBlock(extra_headers, |
| 1057 extra_header_count, |
| 1058 syn_stream.mutable_name_value_block()); |
| 1059 return CreateFramer(false)->SerializeFrame(syn_stream); |
| 1060 } else { |
| 1061 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1062 AddUrlToHeaderBlock(url, push_promise.mutable_name_value_block()); |
| 1063 scoped_ptr<SpdyFrame> push_promise_frame( |
| 1064 CreateFramer(false)->SerializeFrame(push_promise)); |
| 1065 |
| 1066 // Use SynStreamIR to create HEADERS+PRIORITY. Direct creation breaks |
| 1067 // framer. |
| 1068 SpdySynStreamIR headers(stream_id); |
| 1069 SetPriority(LOWEST, &headers); |
| 1070 headers.SetHeader("hello", "bye"); |
| 1071 headers.SetHeader(GetStatusKey(), status); |
| 1072 headers.SetHeader("location", location); |
| 1073 AppendToHeaderBlock( |
| 1074 extra_headers, extra_header_count, headers.mutable_name_value_block()); |
| 1075 scoped_ptr<SpdyFrame> headers_frame( |
| 1076 CreateFramer(false)->SerializeFrame(headers)); |
| 1077 |
| 1078 int joint_data_size = push_promise_frame->size() + headers_frame->size(); |
| 1079 scoped_ptr<char[]> data(new char[joint_data_size]); |
| 1080 const SpdyFrame* frames[2] = { |
| 1081 push_promise_frame.get(), headers_frame.get(), |
| 1082 }; |
| 1083 int combined_size = |
| 1084 CombineFrames(frames, arraysize(frames), data.get(), joint_data_size); |
| 1085 DCHECK_EQ(combined_size, joint_data_size); |
| 1086 return new SpdyFrame(data.release(), joint_data_size, true); |
1030 } | 1087 } |
1031 (*headers)["location"] = location; | 1088 } |
1032 AddUrlToHeaderBlock(url, headers.get()); | 1089 |
1033 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 1090 SpdyFrame* SpdyTestUtil::ConstructInitialSpdyPushFrame( |
1034 return ConstructSpdyControlFrame(headers.Pass(), | 1091 scoped_ptr<SpdyHeaderBlock> headers, |
1035 false, | 1092 int stream_id, |
1036 stream_id, | 1093 int associated_stream_id) { |
1037 LOWEST, | 1094 if (spdy_version() < SPDY4) { |
1038 SYN_STREAM, | 1095 SpdySynStreamIR syn_stream(stream_id); |
1039 CONTROL_FLAG_NONE, | 1096 syn_stream.set_associated_to_stream_id(associated_stream_id); |
1040 associated_stream_id); | 1097 SetPriority(LOWEST, &syn_stream); |
| 1098 syn_stream.set_name_value_block(*headers); |
| 1099 return CreateFramer(false)->SerializeFrame(syn_stream); |
| 1100 } else { |
| 1101 SpdyPushPromiseIR push_promise(associated_stream_id, stream_id); |
| 1102 push_promise.set_name_value_block(*headers); |
| 1103 return CreateFramer(false)->SerializeFrame(push_promise); |
| 1104 } |
1041 } | 1105 } |
1042 | 1106 |
1043 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( | 1107 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( |
1044 int stream_id, | 1108 int stream_id, |
1045 const char* const extra_headers[], | 1109 const char* const extra_headers[], |
1046 int extra_header_count) { | 1110 int extra_header_count) { |
1047 SpdyHeadersIR headers(stream_id); | 1111 SpdyHeadersIR headers(stream_id); |
1048 headers.SetHeader(GetStatusKey(), "200 OK"); | 1112 headers.SetHeader(GetStatusKey(), "200 OK"); |
1049 MaybeAddVersionHeader(&headers); | 1113 MaybeAddVersionHeader(&headers); |
1050 AppendToHeaderBlock(extra_headers, extra_header_count, | 1114 AppendToHeaderBlock(extra_headers, extra_header_count, |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 } | 1311 } |
1248 } | 1312 } |
1249 | 1313 |
1250 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1314 void SpdyTestUtil::SetPriority(RequestPriority priority, |
1251 SpdySynStreamIR* ir) const { | 1315 SpdySynStreamIR* ir) const { |
1252 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1316 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
1253 priority, spdy_version())); | 1317 priority, spdy_version())); |
1254 } | 1318 } |
1255 | 1319 |
1256 } // namespace net | 1320 } // namespace net |
OLD | NEW |