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