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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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_framer.h ('k') | net/spdy/spdy_framer_test.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_framer.h" 5 #include "net/spdy/spdy_framer.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 if (!(cookie[value_start] == ' ' || cookie[value_start] == '\t')) { 54 if (!(cookie[value_start] == ' ' || cookie[value_start] == '\t')) {
55 break; 55 break;
56 } 56 }
57 } 57 }
58 return (pos == 0) && ((cookie.size() - value_start) == 0); 58 return (pos == 0) && ((cookie.size() - value_start) == 0);
59 } 59 }
60 #endif // !defined(USE_SYSTEM_ZLIB) 60 #endif // !defined(USE_SYSTEM_ZLIB)
61 61
62 // Pack parent stream ID and exclusive flag into the format used by HTTP/2 62 // Pack parent stream ID and exclusive flag into the format used by HTTP/2
63 // headers and priority frames. 63 // headers and priority frames.
64 uint32 PackStreamDependencyValues(bool exclusive, 64 uint32_t PackStreamDependencyValues(bool exclusive,
65 SpdyStreamId parent_stream_id) { 65 SpdyStreamId parent_stream_id) {
66 // Make sure the highest-order bit in the parent stream id is zeroed out. 66 // Make sure the highest-order bit in the parent stream id is zeroed out.
67 uint32 parent = parent_stream_id & 0x7fffffff; 67 uint32_t parent = parent_stream_id & 0x7fffffff;
68 // Set the one-bit exclusivity flag. 68 // Set the one-bit exclusivity flag.
69 uint32 e_bit = exclusive ? 0x80000000 : 0; 69 uint32_t e_bit = exclusive ? 0x80000000 : 0;
70 return parent | e_bit; 70 return parent | e_bit;
71 } 71 }
72 72
73 // Unpack parent stream ID and exclusive flag from the format used by HTTP/2 73 // Unpack parent stream ID and exclusive flag from the format used by HTTP/2
74 // headers and priority frames. 74 // headers and priority frames.
75 void UnpackStreamDependencyValues(uint32 packed, 75 void UnpackStreamDependencyValues(uint32_t packed,
76 bool* exclusive, 76 bool* exclusive,
77 SpdyStreamId* parent_stream_id) { 77 SpdyStreamId* parent_stream_id) {
78 *exclusive = (packed >> 31) != 0; 78 *exclusive = (packed >> 31) != 0;
79 // Zero out the highest-order bit to get the parent stream id. 79 // Zero out the highest-order bit to get the parent stream id.
80 *parent_stream_id = packed & 0x7fffffff; 80 *parent_stream_id = packed & 0x7fffffff;
81 } 81 }
82 82
83 struct DictionaryIds { 83 struct DictionaryIds {
84 DictionaryIds() 84 DictionaryIds()
85 : v2_dictionary_id(CalculateDictionaryId(kV2Dictionary, kV2DictionarySize)), 85 : v2_dictionary_id(CalculateDictionaryId(kV2Dictionary, kV2DictionarySize)),
86 v3_dictionary_id(CalculateDictionaryId(kV3Dictionary, kV3DictionarySize)) 86 v3_dictionary_id(CalculateDictionaryId(kV3Dictionary, kV3DictionarySize))
87 {} 87 {}
88 const uLong v2_dictionary_id; 88 const uLong v2_dictionary_id;
89 const uLong v3_dictionary_id; 89 const uLong v3_dictionary_id;
90 }; 90 };
91 91
92 // Adler ID for the SPDY header compressor dictionaries. Note that they are 92 // Adler ID for the SPDY header compressor dictionaries. Note that they are
93 // initialized lazily to avoid static initializers. 93 // initialized lazily to avoid static initializers.
94 base::LazyInstance<DictionaryIds>::Leaky g_dictionary_ids; 94 base::LazyInstance<DictionaryIds>::Leaky g_dictionary_ids;
95 95
96 // Used to indicate no flags in a SPDY flags field. 96 // Used to indicate no flags in a SPDY flags field.
97 const uint8 kNoFlags = 0; 97 const uint8_t kNoFlags = 0;
98 98
99 // Wire sizes of priority payloads. 99 // Wire sizes of priority payloads.
100 const size_t kPriorityDependencyPayloadSize = 4; 100 const size_t kPriorityDependencyPayloadSize = 4;
101 const size_t kPriorityWeightPayloadSize = 1; 101 const size_t kPriorityWeightPayloadSize = 1;
102 102
103 // Wire size of pad length field. 103 // Wire size of pad length field.
104 const size_t kPadLengthFieldSize = 1; 104 const size_t kPadLengthFieldSize = 1;
105 105
106 } // namespace 106 } // namespace
107 107
(...skipping 20 matching lines...) Expand all
128 #else 128 #else
129 #define CHANGE_STATE(newstate) \ 129 #define CHANGE_STATE(newstate) \
130 do { \ 130 do { \
131 DCHECK(state_ != SPDY_ERROR); \ 131 DCHECK(state_ != SPDY_ERROR); \
132 DCHECK_EQ(previous_state_, state_); \ 132 DCHECK_EQ(previous_state_, state_); \
133 previous_state_ = state_; \ 133 previous_state_ = state_; \
134 state_ = newstate; \ 134 state_ = newstate; \
135 } while (false) 135 } while (false)
136 #endif 136 #endif
137 137
138 SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat( 138 SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(SpdyMajorVersion version,
139 SpdyMajorVersion version, uint32 wire) { 139 uint32_t wire) {
140 if (version < SPDY3) { 140 if (version < SPDY3) {
141 ConvertFlagsAndIdForSpdy2(&wire); 141 ConvertFlagsAndIdForSpdy2(&wire);
142 } 142 }
143 return SettingsFlagsAndId(base::NetToHost32(wire) >> 24, 143 return SettingsFlagsAndId(base::NetToHost32(wire) >> 24,
144 base::NetToHost32(wire) & 0x00ffffff); 144 base::NetToHost32(wire) & 0x00ffffff);
145 } 145 }
146 146
147 SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id) 147 SettingsFlagsAndId::SettingsFlagsAndId(uint8_t flags, uint32_t id)
148 : flags_(flags), id_(id & 0x00ffffff) { 148 : flags_(flags), id_(id & 0x00ffffff) {
149 LOG_IF(DFATAL, id > (1u << 24)) << "SPDY setting ID too large: " << id; 149 LOG_IF(DFATAL, id > (1u << 24)) << "SPDY setting ID too large: " << id;
150 } 150 }
151 151
152 uint32 SettingsFlagsAndId::GetWireFormat(SpdyMajorVersion version) 152 uint32_t SettingsFlagsAndId::GetWireFormat(SpdyMajorVersion version) const {
153 const { 153 uint32_t wire =
154 uint32 wire =
155 base::HostToNet32(id_ & 0x00ffffff) | base::HostToNet32(flags_ << 24); 154 base::HostToNet32(id_ & 0x00ffffff) | base::HostToNet32(flags_ << 24);
156 if (version < SPDY3) { 155 if (version < SPDY3) {
157 ConvertFlagsAndIdForSpdy2(&wire); 156 ConvertFlagsAndIdForSpdy2(&wire);
158 } 157 }
159 return wire; 158 return wire;
160 } 159 }
161 160
162 // SPDY 2 had a bug in it with respect to byte ordering of id/flags field. 161 // SPDY 2 had a bug in it with respect to byte ordering of id/flags field.
163 // This method is used to preserve buggy behavior and works on both 162 // This method is used to preserve buggy behavior and works on both
164 // little-endian and big-endian hosts. 163 // little-endian and big-endian hosts.
165 // This method is also bidirectional (can be used to translate SPDY 2 to SPDY 3 164 // This method is also bidirectional (can be used to translate SPDY 2 to SPDY 3
166 // as well as vice versa). 165 // as well as vice versa).
167 void SettingsFlagsAndId::ConvertFlagsAndIdForSpdy2(uint32* val) { 166 void SettingsFlagsAndId::ConvertFlagsAndIdForSpdy2(uint32_t* val) {
168 uint8* wire_array = reinterpret_cast<uint8*>(val); 167 uint8_t* wire_array = reinterpret_cast<uint8_t*>(val);
169 std::swap(wire_array[0], wire_array[3]); 168 std::swap(wire_array[0], wire_array[3]);
170 std::swap(wire_array[1], wire_array[2]); 169 std::swap(wire_array[1], wire_array[2]);
171 } 170 }
172 171
173 bool SpdyFramerVisitorInterface::OnGoAwayFrameData(const char* goaway_data, 172 bool SpdyFramerVisitorInterface::OnGoAwayFrameData(const char* goaway_data,
174 size_t len) { 173 size_t len) {
175 return true; 174 return true;
176 } 175 }
177 176
178 bool SpdyFramerVisitorInterface::OnRstStreamFrameData( 177 bool SpdyFramerVisitorInterface::OnRstStreamFrameData(
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 SpdyFrameReader reader(current_frame_buffer_.data(), 735 SpdyFrameReader reader(current_frame_buffer_.data(),
737 current_frame_buffer_.len()); 736 current_frame_buffer_.len());
738 bool is_control_frame = false; 737 bool is_control_frame = false;
739 738
740 int control_frame_type_field = 739 int control_frame_type_field =
741 SpdyConstants::DataFrameType(protocol_version()); 740 SpdyConstants::DataFrameType(protocol_version());
742 // ProcessControlFrameHeader() will set current_frame_type_ to the 741 // ProcessControlFrameHeader() will set current_frame_type_ to the
743 // correct value if this is a valid control frame. 742 // correct value if this is a valid control frame.
744 current_frame_type_ = DATA; 743 current_frame_type_ = DATA;
745 if (protocol_version() <= SPDY3) { 744 if (protocol_version() <= SPDY3) {
746 uint16 version = 0; 745 uint16_t version = 0;
747 bool successful_read = reader.ReadUInt16(&version); 746 bool successful_read = reader.ReadUInt16(&version);
748 DCHECK(successful_read); 747 DCHECK(successful_read);
749 is_control_frame = (version & kControlFlagMask) != 0; 748 is_control_frame = (version & kControlFlagMask) != 0;
750 version &= ~kControlFlagMask; // Only valid for control frames. 749 version &= ~kControlFlagMask; // Only valid for control frames.
751 if (is_control_frame) { 750 if (is_control_frame) {
752 // We check version before we check validity: version can never be 751 // We check version before we check validity: version can never be
753 // 'invalid', it can only be unsupported. 752 // 'invalid', it can only be unsupported.
754 if (version < SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) || 753 if (version < SpdyConstants::SerializeMajorVersion(SPDY_MIN_VERSION) ||
755 version > SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION) || 754 version > SpdyConstants::SerializeMajorVersion(SPDY_MAX_VERSION) ||
756 SpdyConstants::ParseMajorVersion(version) != protocol_version()) { 755 SpdyConstants::ParseMajorVersion(version) != protocol_version()) {
757 // Version does not match the version the framer was initialized with. 756 // Version does not match the version the framer was initialized with.
758 DVLOG(1) << "Unsupported SPDY version " 757 DVLOG(1) << "Unsupported SPDY version "
759 << version 758 << version
760 << " (expected " << protocol_version() << ")"; 759 << " (expected " << protocol_version() << ")";
761 set_error(SPDY_UNSUPPORTED_VERSION); 760 set_error(SPDY_UNSUPPORTED_VERSION);
762 return 0; 761 return 0;
763 } 762 }
764 // We check control_frame_type_field's validity in 763 // We check control_frame_type_field's validity in
765 // ProcessControlFrameHeader(). 764 // ProcessControlFrameHeader().
766 uint16 control_frame_type_field_uint16; 765 uint16_t control_frame_type_field_uint16;
767 successful_read = reader.ReadUInt16(&control_frame_type_field_uint16); 766 successful_read = reader.ReadUInt16(&control_frame_type_field_uint16);
768 control_frame_type_field = control_frame_type_field_uint16; 767 control_frame_type_field = control_frame_type_field_uint16;
769 } else { 768 } else {
770 reader.Rewind(); 769 reader.Rewind();
771 successful_read = reader.ReadUInt31(&current_frame_stream_id_); 770 successful_read = reader.ReadUInt31(&current_frame_stream_id_);
772 } 771 }
773 DCHECK(successful_read); 772 DCHECK(successful_read);
774 773
775 successful_read = reader.ReadUInt8(&current_frame_flags_); 774 successful_read = reader.ReadUInt8(&current_frame_flags_);
776 DCHECK(successful_read); 775 DCHECK(successful_read);
777 776
778 uint32 length_field = 0; 777 uint32_t length_field = 0;
779 successful_read = reader.ReadUInt24(&length_field); 778 successful_read = reader.ReadUInt24(&length_field);
780 DCHECK(successful_read); 779 DCHECK(successful_read);
781 remaining_data_length_ = length_field; 780 remaining_data_length_ = length_field;
782 current_frame_length_ = remaining_data_length_ + reader.GetBytesConsumed(); 781 current_frame_length_ = remaining_data_length_ + reader.GetBytesConsumed();
783 } else { 782 } else {
784 uint32 length_field = 0; 783 uint32_t length_field = 0;
785 bool successful_read = reader.ReadUInt24(&length_field); 784 bool successful_read = reader.ReadUInt24(&length_field);
786 DCHECK(successful_read); 785 DCHECK(successful_read);
787 786
788 uint8 control_frame_type_field_uint8; 787 uint8_t control_frame_type_field_uint8;
789 successful_read = reader.ReadUInt8(&control_frame_type_field_uint8); 788 successful_read = reader.ReadUInt8(&control_frame_type_field_uint8);
790 DCHECK(successful_read); 789 DCHECK(successful_read);
791 // We check control_frame_type_field's validity in 790 // We check control_frame_type_field's validity in
792 // ProcessControlFrameHeader(). 791 // ProcessControlFrameHeader().
793 control_frame_type_field = control_frame_type_field_uint8; 792 control_frame_type_field = control_frame_type_field_uint8;
794 is_control_frame = control_frame_type_field != 793 is_control_frame = control_frame_type_field !=
795 SpdyConstants::SerializeFrameType(protocol_version(), DATA); 794 SpdyConstants::SerializeFrameType(protocol_version(), DATA);
796 795
797 if (is_control_frame) { 796 if (is_control_frame) {
798 current_frame_length_ = length_field + GetControlFrameHeaderSize(); 797 current_frame_length_ = length_field + GetControlFrameHeaderSize();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 845 }
847 846
848 // if we're here, then we have the common header all received. 847 // if we're here, then we have the common header all received.
849 if (!is_control_frame) { 848 if (!is_control_frame) {
850 if (protocol_version() > SPDY3) { 849 if (protocol_version() > SPDY3) {
851 // Catch bogus tests sending oversized DATA frames. 850 // Catch bogus tests sending oversized DATA frames.
852 DCHECK_GE(GetFrameMaximumSize(), current_frame_length_) 851 DCHECK_GE(GetFrameMaximumSize(), current_frame_length_)
853 << "DATA frame too large for SPDY >= 4."; 852 << "DATA frame too large for SPDY >= 4.";
854 } 853 }
855 854
856 uint8 valid_data_flags = 0; 855 uint8_t valid_data_flags = 0;
857 if (protocol_version() > SPDY3) { 856 if (protocol_version() > SPDY3) {
858 valid_data_flags = 857 valid_data_flags =
859 DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | DATA_FLAG_PADDED; 858 DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | DATA_FLAG_PADDED;
860 } else { 859 } else {
861 valid_data_flags = DATA_FLAG_FIN; 860 valid_data_flags = DATA_FLAG_FIN;
862 } 861 }
863 862
864 if (current_frame_flags_ & ~valid_data_flags) { 863 if (current_frame_flags_ & ~valid_data_flags) {
865 set_error(SPDY_INVALID_DATA_FRAME_FLAGS); 864 set_error(SPDY_INVALID_DATA_FRAME_FLAGS);
866 } else { 865 } else {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 if (current_frame_type_ == RST_STREAM) { 1108 if (current_frame_type_ == RST_STREAM) {
1110 CHANGE_STATE(SPDY_RST_STREAM_FRAME_PAYLOAD); 1109 CHANGE_STATE(SPDY_RST_STREAM_FRAME_PAYLOAD);
1111 return; 1110 return;
1112 } 1111 }
1113 1112
1114 if (current_frame_type_ == ALTSVC) { 1113 if (current_frame_type_ == ALTSVC) {
1115 CHANGE_STATE(SPDY_ALTSVC_FRAME_PAYLOAD); 1114 CHANGE_STATE(SPDY_ALTSVC_FRAME_PAYLOAD);
1116 return; 1115 return;
1117 } 1116 }
1118 // Determine the frame size without variable-length data. 1117 // Determine the frame size without variable-length data.
1119 int32 frame_size_without_variable_data; 1118 int32_t frame_size_without_variable_data;
1120 switch (current_frame_type_) { 1119 switch (current_frame_type_) {
1121 case SYN_STREAM: 1120 case SYN_STREAM:
1122 syn_frame_processed_ = true; 1121 syn_frame_processed_ = true;
1123 frame_size_without_variable_data = GetSynStreamMinimumSize(); 1122 frame_size_without_variable_data = GetSynStreamMinimumSize();
1124 break; 1123 break;
1125 case SYN_REPLY: 1124 case SYN_REPLY:
1126 syn_frame_processed_ = true; 1125 syn_frame_processed_ = true;
1127 frame_size_without_variable_data = GetSynReplyMinimumSize(); 1126 frame_size_without_variable_data = GetSynReplyMinimumSize();
1128 break; 1127 break;
1129 case SETTINGS: 1128 case SETTINGS:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 set_error(SPDY_CONTROL_PAYLOAD_TOO_LARGE); 1166 set_error(SPDY_CONTROL_PAYLOAD_TOO_LARGE);
1168 } 1167 }
1169 return; 1168 return;
1170 } 1169 }
1171 1170
1172 if (frame_size_without_variable_data > 0) { 1171 if (frame_size_without_variable_data > 0) {
1173 // We have a control frame with a header block. We need to parse the 1172 // We have a control frame with a header block. We need to parse the
1174 // remainder of the control frame's header before we can parse the header 1173 // remainder of the control frame's header before we can parse the header
1175 // block. The start of the header block varies with the control type. 1174 // block. The start of the header block varies with the control type.
1176 DCHECK_GE(frame_size_without_variable_data, 1175 DCHECK_GE(frame_size_without_variable_data,
1177 static_cast<int32>(current_frame_buffer_.len())); 1176 static_cast<int32_t>(current_frame_buffer_.len()));
1178 remaining_control_header_ = 1177 remaining_control_header_ =
1179 frame_size_without_variable_data - current_frame_buffer_.len(); 1178 frame_size_without_variable_data - current_frame_buffer_.len();
1180 1179
1181 CHANGE_STATE(SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK); 1180 CHANGE_STATE(SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK);
1182 return; 1181 return;
1183 } 1182 }
1184 1183
1185 CHANGE_STATE(SPDY_CONTROL_FRAME_PAYLOAD); 1184 CHANGE_STATE(SPDY_CONTROL_FRAME_PAYLOAD);
1186 } 1185 }
1187 1186
1188 size_t SpdyFramer::UpdateCurrentFrameBuffer(const char** data, size_t* len, 1187 size_t SpdyFramer::UpdateCurrentFrameBuffer(const char** data, size_t* len,
1189 size_t max_bytes) { 1188 size_t max_bytes) {
1190 size_t bytes_to_read = std::min(*len, max_bytes); 1189 size_t bytes_to_read = std::min(*len, max_bytes);
1191 if (bytes_to_read > 0) { 1190 if (bytes_to_read > 0) {
1192 current_frame_buffer_.CopyFrom(*data, bytes_to_read); 1191 current_frame_buffer_.CopyFrom(*data, bytes_to_read);
1193 *data += bytes_to_read; 1192 *data += bytes_to_read;
1194 *len -= bytes_to_read; 1193 *len -= bytes_to_read;
1195 } 1194 }
1196 return bytes_to_read; 1195 return bytes_to_read;
1197 } 1196 }
1198 1197
1199 size_t SpdyFramer::GetSerializedLength( 1198 size_t SpdyFramer::GetSerializedLength(
1200 const SpdyMajorVersion spdy_version, 1199 const SpdyMajorVersion spdy_version,
1201 const SpdyHeaderBlock* headers) { 1200 const SpdyHeaderBlock* headers) {
1202 const size_t num_name_value_pairs_size 1201 const size_t num_name_value_pairs_size =
1203 = (spdy_version < SPDY3) ? sizeof(uint16) : sizeof(uint32); 1202 (spdy_version < SPDY3) ? sizeof(uint16_t) : sizeof(uint32_t);
1204 const size_t length_of_name_size = num_name_value_pairs_size; 1203 const size_t length_of_name_size = num_name_value_pairs_size;
1205 const size_t length_of_value_size = num_name_value_pairs_size; 1204 const size_t length_of_value_size = num_name_value_pairs_size;
1206 1205
1207 size_t total_length = num_name_value_pairs_size; 1206 size_t total_length = num_name_value_pairs_size;
1208 for (const auto& header : *headers) { 1207 for (const auto& header : *headers) {
1209 // We add space for the length of the name and the length of the value as 1208 // We add space for the length of the name and the length of the value as
1210 // well as the length of the name and the length of the value. 1209 // well as the length of the name and the length of the value.
1211 total_length += length_of_name_size + header.first.size() + 1210 total_length += length_of_name_size + header.first.size() +
1212 length_of_value_size + header.second.size(); 1211 length_of_value_size + header.second.size();
1213 } 1212 }
1214 return total_length; 1213 return total_length;
1215 } 1214 }
1216 1215
1217 void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame, 1216 void SpdyFramer::WriteHeaderBlock(SpdyFrameBuilder* frame,
1218 const SpdyMajorVersion spdy_version, 1217 const SpdyMajorVersion spdy_version,
1219 const SpdyHeaderBlock* headers) { 1218 const SpdyHeaderBlock* headers) {
1220 if (spdy_version < SPDY3) { 1219 if (spdy_version < SPDY3) {
1221 frame->WriteUInt16(static_cast<uint16>(headers->size())); 1220 frame->WriteUInt16(static_cast<uint16_t>(headers->size()));
1222 } else { 1221 } else {
1223 frame->WriteUInt32(headers->size()); 1222 frame->WriteUInt32(headers->size());
1224 } 1223 }
1225 SpdyHeaderBlock::const_iterator it; 1224 SpdyHeaderBlock::const_iterator it;
1226 for (it = headers->begin(); it != headers->end(); ++it) { 1225 for (it = headers->begin(); it != headers->end(); ++it) {
1227 if (spdy_version < SPDY3) { 1226 if (spdy_version < SPDY3) {
1228 frame->WriteStringPiece16(it->first); 1227 frame->WriteStringPiece16(it->first);
1229 frame->WriteStringPiece16(it->second); 1228 frame->WriteStringPiece16(it->second);
1230 } else { 1229 } else {
1231 frame->WriteStringPiece32(it->first); 1230 frame->WriteStringPiece32(it->first);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 reader.Seek(2); 1500 reader.Seek(2);
1502 } 1501 }
1503 if (protocol_version() > SPDY3 && 1502 if (protocol_version() > SPDY3 &&
1504 !(current_frame_flags_ & HEADERS_FLAG_END_HEADERS) && 1503 !(current_frame_flags_ & HEADERS_FLAG_END_HEADERS) &&
1505 current_frame_type_ == HEADERS) { 1504 current_frame_type_ == HEADERS) {
1506 expect_continuation_ = current_frame_stream_id_; 1505 expect_continuation_ = current_frame_stream_id_;
1507 end_stream_when_done_ = current_frame_flags_ & CONTROL_FLAG_FIN; 1506 end_stream_when_done_ = current_frame_flags_ & CONTROL_FLAG_FIN;
1508 } 1507 }
1509 if (protocol_version() > SPDY3 && 1508 if (protocol_version() > SPDY3 &&
1510 current_frame_flags_ & HEADERS_FLAG_PADDED) { 1509 current_frame_flags_ & HEADERS_FLAG_PADDED) {
1511 uint8 pad_payload_len = 0; 1510 uint8_t pad_payload_len = 0;
1512 DCHECK_EQ(remaining_padding_payload_length_, 0u); 1511 DCHECK_EQ(remaining_padding_payload_length_, 0u);
1513 successful_read = reader.ReadUInt8(&pad_payload_len); 1512 successful_read = reader.ReadUInt8(&pad_payload_len);
1514 DCHECK(successful_read); 1513 DCHECK(successful_read);
1515 remaining_padding_payload_length_ = pad_payload_len; 1514 remaining_padding_payload_length_ = pad_payload_len;
1516 } 1515 }
1517 const bool has_priority = 1516 const bool has_priority =
1518 (current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0; 1517 (current_frame_flags_ & HEADERS_FLAG_PRIORITY) != 0;
1519 SpdyPriority priority = 0; 1518 SpdyPriority priority = 0;
1520 uint32 parent_stream_id = 0; 1519 uint32_t parent_stream_id = 0;
1521 bool exclusive = false; 1520 bool exclusive = false;
1522 if (protocol_version() > SPDY3 && has_priority) { 1521 if (protocol_version() > SPDY3 && has_priority) {
1523 uint32 stream_dependency; 1522 uint32_t stream_dependency;
1524 successful_read = reader.ReadUInt32(&stream_dependency); 1523 successful_read = reader.ReadUInt32(&stream_dependency);
1525 DCHECK(successful_read); 1524 DCHECK(successful_read);
1526 UnpackStreamDependencyValues(stream_dependency, &exclusive, 1525 UnpackStreamDependencyValues(stream_dependency, &exclusive,
1527 &parent_stream_id); 1526 &parent_stream_id);
1528 1527
1529 uint8 weight = 0; 1528 uint8_t weight = 0;
1530 successful_read = reader.ReadUInt8(&weight); 1529 successful_read = reader.ReadUInt8(&weight);
1531 if (successful_read) { 1530 if (successful_read) {
1532 priority = MapWeightToPriority(weight); 1531 priority = MapWeightToPriority(weight);
1533 } 1532 }
1534 } 1533 }
1535 DCHECK(reader.IsDoneReading()); 1534 DCHECK(reader.IsDoneReading());
1536 if (debug_visitor_) { 1535 if (debug_visitor_) {
1537 debug_visitor_->OnReceiveCompressedFrame( 1536 debug_visitor_->OnReceiveCompressedFrame(
1538 current_frame_stream_id_, 1537 current_frame_stream_id_,
1539 current_frame_type_, 1538 current_frame_type_,
(...skipping 18 matching lines...) Expand all
1558 { 1557 {
1559 DCHECK_LT(SPDY3, protocol_version()); 1558 DCHECK_LT(SPDY3, protocol_version());
1560 if (current_frame_stream_id_ == 0) { 1559 if (current_frame_stream_id_ == 0) {
1561 set_error(SPDY_INVALID_CONTROL_FRAME); 1560 set_error(SPDY_INVALID_CONTROL_FRAME);
1562 break; 1561 break;
1563 } 1562 }
1564 bool successful_read = true; 1563 bool successful_read = true;
1565 if (protocol_version() > SPDY3 && 1564 if (protocol_version() > SPDY3 &&
1566 current_frame_flags_ & PUSH_PROMISE_FLAG_PADDED) { 1565 current_frame_flags_ & PUSH_PROMISE_FLAG_PADDED) {
1567 DCHECK_EQ(remaining_padding_payload_length_, 0u); 1566 DCHECK_EQ(remaining_padding_payload_length_, 0u);
1568 uint8 pad_payload_len = 0; 1567 uint8_t pad_payload_len = 0;
1569 successful_read = reader.ReadUInt8(&pad_payload_len); 1568 successful_read = reader.ReadUInt8(&pad_payload_len);
1570 DCHECK(successful_read); 1569 DCHECK(successful_read);
1571 remaining_padding_payload_length_ = pad_payload_len; 1570 remaining_padding_payload_length_ = pad_payload_len;
1572 } 1571 }
1573 } 1572 }
1574 { 1573 {
1575 SpdyStreamId promised_stream_id = kInvalidStream; 1574 SpdyStreamId promised_stream_id = kInvalidStream;
1576 bool successful_read = reader.ReadUInt31(&promised_stream_id); 1575 bool successful_read = reader.ReadUInt31(&promised_stream_id);
1577 DCHECK(successful_read); 1576 DCHECK(successful_read);
1578 DCHECK(reader.IsDoneReading()); 1577 DCHECK(reader.IsDoneReading());
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 1785
1787 ProcessControlFrameHeaderBlock(frame->data(), frame->size(), false); 1786 ProcessControlFrameHeaderBlock(frame->data(), frame->size(), false);
1788 1787
1789 remaining_padding_payload_length_ = remaining_padding; 1788 remaining_padding_payload_length_ = remaining_padding;
1790 remaining_data_length_ = remaining_padding; 1789 remaining_data_length_ = remaining_padding;
1791 } 1790 }
1792 1791
1793 bool SpdyFramer::ProcessSetting(const char* data) { 1792 bool SpdyFramer::ProcessSetting(const char* data) {
1794 int id_field; 1793 int id_field;
1795 SpdySettingsIds id; 1794 SpdySettingsIds id;
1796 uint8 flags = 0; 1795 uint8_t flags = 0;
1797 uint32 value; 1796 uint32_t value;
1798 1797
1799 // Extract fields. 1798 // Extract fields.
1800 // Maintain behavior of old SPDY 2 bug with byte ordering of flags/id. 1799 // Maintain behavior of old SPDY 2 bug with byte ordering of flags/id.
1801 if (protocol_version() <= SPDY3) { 1800 if (protocol_version() <= SPDY3) {
1802 const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data)); 1801 const uint32_t id_and_flags_wire =
1802 *(reinterpret_cast<const uint32_t*>(data));
1803 SettingsFlagsAndId id_and_flags = 1803 SettingsFlagsAndId id_and_flags =
1804 SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire); 1804 SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire);
1805 id_field = id_and_flags.id(); 1805 id_field = id_and_flags.id();
1806 flags = id_and_flags.flags(); 1806 flags = id_and_flags.flags();
1807 value = base::NetToHost32(*(reinterpret_cast<const uint32*>(data + 4))); 1807 value = base::NetToHost32(*(reinterpret_cast<const uint32_t*>(data + 4)));
1808 } else { 1808 } else {
1809 id_field = base::NetToHost16(*(reinterpret_cast<const uint16*>(data))); 1809 id_field = base::NetToHost16(*(reinterpret_cast<const uint16_t*>(data)));
1810 value = base::NetToHost32(*(reinterpret_cast<const uint32*>(data + 2))); 1810 value = base::NetToHost32(*(reinterpret_cast<const uint32_t*>(data + 2)));
1811 } 1811 }
1812 1812
1813 // Validate id. 1813 // Validate id.
1814 if (!SpdyConstants::IsValidSettingId(protocol_version(), id_field)) { 1814 if (!SpdyConstants::IsValidSettingId(protocol_version(), id_field)) {
1815 DLOG(WARNING) << "Unknown SETTINGS ID: " << id_field; 1815 DLOG(WARNING) << "Unknown SETTINGS ID: " << id_field;
1816 if (protocol_version() <= SPDY3) { 1816 if (protocol_version() <= SPDY3) {
1817 return false; 1817 return false;
1818 } else { 1818 } else {
1819 // In HTTP2 we ignore unknown settings for extensibility. 1819 // In HTTP2 we ignore unknown settings for extensibility.
1820 return true; 1820 return true;
1821 } 1821 }
1822 } 1822 }
1823 id = SpdyConstants::ParseSettingId(protocol_version(), id_field); 1823 id = SpdyConstants::ParseSettingId(protocol_version(), id_field);
1824 1824
1825 if (protocol_version() <= SPDY3) { 1825 if (protocol_version() <= SPDY3) {
1826 // Detect duplicates. 1826 // Detect duplicates.
1827 if (id <= settings_scratch_.last_setting_id) { 1827 if (id <= settings_scratch_.last_setting_id) {
1828 DLOG(WARNING) << "Duplicate entry or invalid ordering for id " << id 1828 DLOG(WARNING) << "Duplicate entry or invalid ordering for id " << id
1829 << " in " << display_protocol_ << " SETTINGS frame " 1829 << " in " << display_protocol_ << " SETTINGS frame "
1830 << "(last setting id was " 1830 << "(last setting id was "
1831 << settings_scratch_.last_setting_id << ")."; 1831 << settings_scratch_.last_setting_id << ").";
1832 return false; 1832 return false;
1833 } 1833 }
1834 settings_scratch_.last_setting_id = id; 1834 settings_scratch_.last_setting_id = id;
1835 1835
1836 // Validate flags. 1836 // Validate flags.
1837 uint8 kFlagsMask = SETTINGS_FLAG_PLEASE_PERSIST | SETTINGS_FLAG_PERSISTED; 1837 uint8_t kFlagsMask = SETTINGS_FLAG_PLEASE_PERSIST | SETTINGS_FLAG_PERSISTED;
1838 if ((flags & ~(kFlagsMask)) != 0) { 1838 if ((flags & ~(kFlagsMask)) != 0) {
1839 DLOG(WARNING) << "Unknown SETTINGS flags provided for id " << id << ": " 1839 DLOG(WARNING) << "Unknown SETTINGS flags provided for id " << id << ": "
1840 << flags; 1840 << flags;
1841 return false; 1841 return false;
1842 } 1842 }
1843 } 1843 }
1844 1844
1845 // Validation succeeded. Pass on to visitor. 1845 // Validation succeeded. Pass on to visitor.
1846 visitor_->OnSetting(id, flags, value); 1846 visitor_->OnSetting(id, flags, value);
1847 return true; 1847 return true;
(...skipping 10 matching lines...) Expand all
1858 reader.Seek(GetControlFrameHeaderSize()); // Skip frame header. 1858 reader.Seek(GetControlFrameHeaderSize()); // Skip frame header.
1859 1859
1860 // Use frame-specific handlers. 1860 // Use frame-specific handlers.
1861 switch (current_frame_type_) { 1861 switch (current_frame_type_) {
1862 case PING: { 1862 case PING: {
1863 SpdyPingId id = 0; 1863 SpdyPingId id = 0;
1864 bool is_ack = protocol_version() > SPDY3 && 1864 bool is_ack = protocol_version() > SPDY3 &&
1865 (current_frame_flags_ & PING_FLAG_ACK); 1865 (current_frame_flags_ & PING_FLAG_ACK);
1866 bool successful_read = true; 1866 bool successful_read = true;
1867 if (protocol_version() <= SPDY3) { 1867 if (protocol_version() <= SPDY3) {
1868 uint32 id32 = 0; 1868 uint32_t id32 = 0;
1869 successful_read = reader.ReadUInt32(&id32); 1869 successful_read = reader.ReadUInt32(&id32);
1870 id = id32; 1870 id = id32;
1871 } else { 1871 } else {
1872 successful_read = reader.ReadUInt64(&id); 1872 successful_read = reader.ReadUInt64(&id);
1873 } 1873 }
1874 DCHECK(successful_read); 1874 DCHECK(successful_read);
1875 DCHECK(reader.IsDoneReading()); 1875 DCHECK(reader.IsDoneReading());
1876 visitor_->OnPing(id, is_ack); 1876 visitor_->OnPing(id, is_ack);
1877 } 1877 }
1878 break; 1878 break;
1879 case WINDOW_UPDATE: { 1879 case WINDOW_UPDATE: {
1880 uint32 delta_window_size = 0; 1880 uint32_t delta_window_size = 0;
1881 bool successful_read = true; 1881 bool successful_read = true;
1882 if (protocol_version() <= SPDY3) { 1882 if (protocol_version() <= SPDY3) {
1883 successful_read = reader.ReadUInt31(&current_frame_stream_id_); 1883 successful_read = reader.ReadUInt31(&current_frame_stream_id_);
1884 DCHECK(successful_read); 1884 DCHECK(successful_read);
1885 } 1885 }
1886 successful_read = reader.ReadUInt32(&delta_window_size); 1886 successful_read = reader.ReadUInt32(&delta_window_size);
1887 DCHECK(successful_read); 1887 DCHECK(successful_read);
1888 DCHECK(reader.IsDoneReading()); 1888 DCHECK(reader.IsDoneReading());
1889 visitor_->OnWindowUpdate(current_frame_stream_id_, 1889 visitor_->OnWindowUpdate(current_frame_stream_id_,
1890 delta_window_size); 1890 delta_window_size);
1891 } 1891 }
1892 break; 1892 break;
1893 case BLOCKED: { 1893 case BLOCKED: {
1894 DCHECK_LT(SPDY3, protocol_version()); 1894 DCHECK_LT(SPDY3, protocol_version());
1895 DCHECK(reader.IsDoneReading()); 1895 DCHECK(reader.IsDoneReading());
1896 visitor_->OnBlocked(current_frame_stream_id_); 1896 visitor_->OnBlocked(current_frame_stream_id_);
1897 } 1897 }
1898 break; 1898 break;
1899 case PRIORITY: { 1899 case PRIORITY: {
1900 DCHECK_LT(SPDY3, protocol_version()); 1900 DCHECK_LT(SPDY3, protocol_version());
1901 uint32 stream_dependency; 1901 uint32_t stream_dependency;
1902 uint32 parent_stream_id; 1902 uint32_t parent_stream_id;
1903 bool exclusive; 1903 bool exclusive;
1904 uint8 weight; 1904 uint8_t weight;
1905 bool successful_read = reader.ReadUInt32(&stream_dependency); 1905 bool successful_read = reader.ReadUInt32(&stream_dependency);
1906 DCHECK(successful_read); 1906 DCHECK(successful_read);
1907 UnpackStreamDependencyValues(stream_dependency, &exclusive, 1907 UnpackStreamDependencyValues(stream_dependency, &exclusive,
1908 &parent_stream_id); 1908 &parent_stream_id);
1909 1909
1910 successful_read = reader.ReadUInt8(&weight); 1910 successful_read = reader.ReadUInt8(&weight);
1911 DCHECK(successful_read); 1911 DCHECK(successful_read);
1912 DCHECK(reader.IsDoneReading()); 1912 DCHECK(reader.IsDoneReading());
1913 visitor_->OnPriority( 1913 visitor_->OnPriority(
1914 current_frame_stream_id_, parent_stream_id, weight, exclusive); 1914 current_frame_stream_id_, parent_stream_id, weight, exclusive);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1947 // Parse out the last good stream id. 1947 // Parse out the last good stream id.
1948 SpdyFrameReader reader(current_frame_buffer_.data(), 1948 SpdyFrameReader reader(current_frame_buffer_.data(),
1949 current_frame_buffer_.len()); 1949 current_frame_buffer_.len());
1950 reader.Seek(GetControlFrameHeaderSize()); // Seek past frame header. 1950 reader.Seek(GetControlFrameHeaderSize()); // Seek past frame header.
1951 bool successful_read = reader.ReadUInt31(&current_frame_stream_id_); 1951 bool successful_read = reader.ReadUInt31(&current_frame_stream_id_);
1952 DCHECK(successful_read); 1952 DCHECK(successful_read);
1953 1953
1954 // In SPDYv3 and up, frames also specify a status code - parse it out. 1954 // In SPDYv3 and up, frames also specify a status code - parse it out.
1955 SpdyGoAwayStatus status = GOAWAY_OK; 1955 SpdyGoAwayStatus status = GOAWAY_OK;
1956 if (protocol_version() >= SPDY3) { 1956 if (protocol_version() >= SPDY3) {
1957 uint32 status_raw = GOAWAY_OK; 1957 uint32_t status_raw = GOAWAY_OK;
1958 successful_read = reader.ReadUInt32(&status_raw); 1958 successful_read = reader.ReadUInt32(&status_raw);
1959 DCHECK(successful_read); 1959 DCHECK(successful_read);
1960 if (SpdyConstants::IsValidGoAwayStatus(protocol_version(), 1960 if (SpdyConstants::IsValidGoAwayStatus(protocol_version(),
1961 status_raw)) { 1961 status_raw)) {
1962 status = SpdyConstants::ParseGoAwayStatus(protocol_version(), 1962 status = SpdyConstants::ParseGoAwayStatus(protocol_version(),
1963 status_raw); 1963 status_raw);
1964 } else { 1964 } else {
1965 if (protocol_version() > SPDY3) { 1965 if (protocol_version() > SPDY3) {
1966 // Treat unrecognized status codes as INTERNAL_ERROR as 1966 // Treat unrecognized status codes as INTERNAL_ERROR as
1967 // recommended by the HTTP/2 spec. 1967 // recommended by the HTTP/2 spec.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 // Parse out the last good stream id. 2014 // Parse out the last good stream id.
2015 SpdyFrameReader reader(current_frame_buffer_.data(), 2015 SpdyFrameReader reader(current_frame_buffer_.data(),
2016 current_frame_buffer_.len()); 2016 current_frame_buffer_.len());
2017 reader.Seek(GetControlFrameHeaderSize()); // Seek past frame header. 2017 reader.Seek(GetControlFrameHeaderSize()); // Seek past frame header.
2018 if (protocol_version() <= SPDY3) { 2018 if (protocol_version() <= SPDY3) {
2019 bool successful_read = reader.ReadUInt31(&current_frame_stream_id_); 2019 bool successful_read = reader.ReadUInt31(&current_frame_stream_id_);
2020 DCHECK(successful_read); 2020 DCHECK(successful_read);
2021 } 2021 }
2022 2022
2023 SpdyRstStreamStatus status = RST_STREAM_INVALID; 2023 SpdyRstStreamStatus status = RST_STREAM_INVALID;
2024 uint32 status_raw = status; 2024 uint32_t status_raw = status;
2025 bool successful_read = reader.ReadUInt32(&status_raw); 2025 bool successful_read = reader.ReadUInt32(&status_raw);
2026 DCHECK(successful_read); 2026 DCHECK(successful_read);
2027 if (SpdyConstants::IsValidRstStreamStatus(protocol_version(), 2027 if (SpdyConstants::IsValidRstStreamStatus(protocol_version(),
2028 status_raw)) { 2028 status_raw)) {
2029 status = 2029 status =
2030 SpdyConstants::ParseRstStreamStatus(protocol_version(), status_raw); 2030 SpdyConstants::ParseRstStreamStatus(protocol_version(), status_raw);
2031 } else { 2031 } else {
2032 if (protocol_version() > SPDY3) { 2032 if (protocol_version() > SPDY3) {
2033 // Treat unrecognized status codes as INTERNAL_ERROR as 2033 // Treat unrecognized status codes as INTERNAL_ERROR as
2034 // recommended by the HTTP/2 spec. 2034 // recommended by the HTTP/2 spec.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 size_t original_len = len; 2105 size_t original_len = len;
2106 if (current_frame_flags_ & DATA_FLAG_PADDED) { 2106 if (current_frame_flags_ & DATA_FLAG_PADDED) {
2107 if (len != 0) { 2107 if (len != 0) {
2108 if (remaining_data_length_ < kPadLengthFieldSize) { 2108 if (remaining_data_length_ < kPadLengthFieldSize) {
2109 set_error(SPDY_INVALID_DATA_FRAME_FLAGS); 2109 set_error(SPDY_INVALID_DATA_FRAME_FLAGS);
2110 return 0; 2110 return 0;
2111 } 2111 }
2112 2112
2113 static_assert(kPadLengthFieldSize == 1, 2113 static_assert(kPadLengthFieldSize == 1,
2114 "Unexpected pad length field size."); 2114 "Unexpected pad length field size.");
2115 remaining_padding_payload_length_ = *reinterpret_cast<const uint8*>(data); 2115 remaining_padding_payload_length_ =
2116 *reinterpret_cast<const uint8_t*>(data);
2116 ++data; 2117 ++data;
2117 --len; 2118 --len;
2118 --remaining_data_length_; 2119 --remaining_data_length_;
2119 visitor_->OnStreamPadding(current_frame_stream_id_, kPadLengthFieldSize); 2120 visitor_->OnStreamPadding(current_frame_stream_id_, kPadLengthFieldSize);
2120 } else { 2121 } else {
2121 // We don't have the data available for parsing the pad length field. Keep 2122 // We don't have the data available for parsing the pad length field. Keep
2122 // waiting. 2123 // waiting.
2123 return 0; 2124 return 0;
2124 } 2125 }
2125 } 2126 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 } 2201 }
2201 return original_len - len; 2202 return original_len - len;
2202 } 2203 }
2203 2204
2204 bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data, 2205 bool SpdyFramer::ParseHeaderBlockInBuffer(const char* header_data,
2205 size_t header_length, 2206 size_t header_length,
2206 SpdyHeaderBlock* block) const { 2207 SpdyHeaderBlock* block) const {
2207 SpdyFrameReader reader(header_data, header_length); 2208 SpdyFrameReader reader(header_data, header_length);
2208 2209
2209 // Read number of headers. 2210 // Read number of headers.
2210 uint32 num_headers; 2211 uint32_t num_headers;
2211 if (protocol_version() <= SPDY2) { 2212 if (protocol_version() <= SPDY2) {
2212 uint16 temp; 2213 uint16_t temp;
2213 if (!reader.ReadUInt16(&temp)) { 2214 if (!reader.ReadUInt16(&temp)) {
2214 DVLOG(1) << "Unable to read number of headers."; 2215 DVLOG(1) << "Unable to read number of headers.";
2215 return false; 2216 return false;
2216 } 2217 }
2217 num_headers = temp; 2218 num_headers = temp;
2218 } else { 2219 } else {
2219 if (!reader.ReadUInt32(&num_headers)) { 2220 if (!reader.ReadUInt32(&num_headers)) {
2220 DVLOG(1) << "Unable to read number of headers."; 2221 DVLOG(1) << "Unable to read number of headers.";
2221 return false; 2222 return false;
2222 } 2223 }
2223 } 2224 }
2224 2225
2225 // Read each header. 2226 // Read each header.
2226 for (uint32 index = 0; index < num_headers; ++index) { 2227 for (uint32_t index = 0; index < num_headers; ++index) {
2227 base::StringPiece temp; 2228 base::StringPiece temp;
2228 2229
2229 // Read header name. 2230 // Read header name.
2230 if ((protocol_version() <= SPDY2) ? !reader.ReadStringPiece16(&temp) 2231 if ((protocol_version() <= SPDY2) ? !reader.ReadStringPiece16(&temp)
2231 : !reader.ReadStringPiece32(&temp)) { 2232 : !reader.ReadStringPiece32(&temp)) {
2232 DVLOG(1) << "Unable to read header name (" << index + 1 << " of " 2233 DVLOG(1) << "Unable to read header name (" << index + 1 << " of "
2233 << num_headers << ")."; 2234 << num_headers << ").";
2234 return false; 2235 return false;
2235 } 2236 }
2236 std::string name = temp.as_string(); 2237 std::string name = temp.as_string();
(...skipping 22 matching lines...) Expand all
2259 << reader.GetBytesConsumed() << " bytes consumed, from " 2260 << reader.GetBytesConsumed() << " bytes consumed, from "
2260 << header_length; 2261 << header_length;
2261 return false; 2262 return false;
2262 } 2263 }
2263 2264
2264 return true; 2265 return true;
2265 } 2266 }
2266 2267
2267 SpdySerializedFrame* SpdyFramer::SerializeData( 2268 SpdySerializedFrame* SpdyFramer::SerializeData(
2268 const SpdyDataIR& data_ir) const { 2269 const SpdyDataIR& data_ir) const {
2269 uint8 flags = DATA_FLAG_NONE; 2270 uint8_t flags = DATA_FLAG_NONE;
2270 if (data_ir.fin()) { 2271 if (data_ir.fin()) {
2271 flags = DATA_FLAG_FIN; 2272 flags = DATA_FLAG_FIN;
2272 } 2273 }
2273 2274
2274 if (protocol_version() > SPDY3) { 2275 if (protocol_version() > SPDY3) {
2275 int num_padding_fields = 0; 2276 int num_padding_fields = 0;
2276 if (data_ir.padded()) { 2277 if (data_ir.padded()) {
2277 flags |= DATA_FLAG_PADDED; 2278 flags |= DATA_FLAG_PADDED;
2278 ++num_padding_fields; 2279 ++num_padding_fields;
2279 } 2280 }
(...skipping 18 matching lines...) Expand all
2298 SpdyFrameBuilder builder(size, protocol_version()); 2299 SpdyFrameBuilder builder(size, protocol_version());
2299 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags); 2300 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags);
2300 builder.WriteBytes(data_ir.data().data(), data_ir.data().length()); 2301 builder.WriteBytes(data_ir.data().data(), data_ir.data().length());
2301 DCHECK_EQ(size, builder.length()); 2302 DCHECK_EQ(size, builder.length());
2302 return builder.take(); 2303 return builder.take();
2303 } 2304 }
2304 } 2305 }
2305 2306
2306 SpdySerializedFrame* SpdyFramer::SerializeDataFrameHeaderWithPaddingLengthField( 2307 SpdySerializedFrame* SpdyFramer::SerializeDataFrameHeaderWithPaddingLengthField(
2307 const SpdyDataIR& data_ir) const { 2308 const SpdyDataIR& data_ir) const {
2308 uint8 flags = DATA_FLAG_NONE; 2309 uint8_t flags = DATA_FLAG_NONE;
2309 if (data_ir.fin()) { 2310 if (data_ir.fin()) {
2310 flags = DATA_FLAG_FIN; 2311 flags = DATA_FLAG_FIN;
2311 } 2312 }
2312 2313
2313 size_t frame_size = GetDataFrameMinimumSize(); 2314 size_t frame_size = GetDataFrameMinimumSize();
2314 size_t num_padding_fields = 0; 2315 size_t num_padding_fields = 0;
2315 if (protocol_version() > SPDY3) { 2316 if (protocol_version() > SPDY3) {
2316 if (data_ir.padded()) { 2317 if (data_ir.padded()) {
2317 flags |= DATA_FLAG_PADDED; 2318 flags |= DATA_FLAG_PADDED;
2318 ++num_padding_fields; 2319 ++num_padding_fields;
(...skipping 12 matching lines...) Expand all
2331 } else { 2332 } else {
2332 builder.OverwriteLength(*this, data_ir.data().length()); 2333 builder.OverwriteLength(*this, data_ir.data().length());
2333 } 2334 }
2334 DCHECK_EQ(frame_size, builder.length()); 2335 DCHECK_EQ(frame_size, builder.length());
2335 return builder.take(); 2336 return builder.take();
2336 } 2337 }
2337 2338
2338 SpdySerializedFrame* SpdyFramer::SerializeSynStream( 2339 SpdySerializedFrame* SpdyFramer::SerializeSynStream(
2339 const SpdySynStreamIR& syn_stream) { 2340 const SpdySynStreamIR& syn_stream) {
2340 DCHECK_GE(SPDY3, protocol_version()); 2341 DCHECK_GE(SPDY3, protocol_version());
2341 uint8 flags = 0; 2342 uint8_t flags = 0;
2342 if (syn_stream.fin()) { 2343 if (syn_stream.fin()) {
2343 flags |= CONTROL_FLAG_FIN; 2344 flags |= CONTROL_FLAG_FIN;
2344 } 2345 }
2345 if (syn_stream.unidirectional()) { 2346 if (syn_stream.unidirectional()) {
2346 // TODO(hkhalil): invalid for HTTP2. 2347 // TODO(hkhalil): invalid for HTTP2.
2347 flags |= CONTROL_FLAG_UNIDIRECTIONAL; 2348 flags |= CONTROL_FLAG_UNIDIRECTIONAL;
2348 } 2349 }
2349 2350
2350 // Sanitize priority. 2351 // Sanitize priority.
2351 uint8 priority = syn_stream.priority(); 2352 uint8_t priority = syn_stream.priority();
2352 if (priority > GetLowestPriority()) { 2353 if (priority > GetLowestPriority()) {
2353 DLOG(DFATAL) << "Priority out-of-bounds."; 2354 DLOG(DFATAL) << "Priority out-of-bounds.";
2354 priority = GetLowestPriority(); 2355 priority = GetLowestPriority();
2355 } 2356 }
2356 2357
2357 // The size of this frame, including variable-length header block. 2358 // The size of this frame, including variable-length header block.
2358 size_t size = GetSynStreamMinimumSize() + 2359 size_t size = GetSynStreamMinimumSize() +
2359 GetSerializedLength(syn_stream.header_block()); 2360 GetSerializedLength(syn_stream.header_block());
2360 2361
2361 SpdyFrameBuilder builder(size, protocol_version()); 2362 SpdyFrameBuilder builder(size, protocol_version());
(...skipping 13 matching lines...) Expand all
2375 payload_len, 2376 payload_len,
2376 builder.length()); 2377 builder.length());
2377 } 2378 }
2378 2379
2379 return builder.take(); 2380 return builder.take();
2380 } 2381 }
2381 2382
2382 SpdySerializedFrame* SpdyFramer::SerializeSynReply( 2383 SpdySerializedFrame* SpdyFramer::SerializeSynReply(
2383 const SpdySynReplyIR& syn_reply) { 2384 const SpdySynReplyIR& syn_reply) {
2384 DCHECK_GE(SPDY3, protocol_version()); 2385 DCHECK_GE(SPDY3, protocol_version());
2385 uint8 flags = 0; 2386 uint8_t flags = 0;
2386 if (syn_reply.fin()) { 2387 if (syn_reply.fin()) {
2387 flags |= CONTROL_FLAG_FIN; 2388 flags |= CONTROL_FLAG_FIN;
2388 } 2389 }
2389 2390
2390 // The size of this frame, including variable-length header block. 2391 // The size of this frame, including variable-length header block.
2391 const size_t size = 2392 const size_t size =
2392 GetSynReplyMinimumSize() + GetSerializedLength(syn_reply.header_block()); 2393 GetSynReplyMinimumSize() + GetSerializedLength(syn_reply.header_block());
2393 2394
2394 SpdyFrameBuilder builder(size, protocol_version()); 2395 SpdyFrameBuilder builder(size, protocol_version());
2395 if (protocol_version() <= SPDY3) { 2396 if (protocol_version() <= SPDY3) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2439 2440
2440 builder.WriteUInt32(SpdyConstants::SerializeRstStreamStatus( 2441 builder.WriteUInt32(SpdyConstants::SerializeRstStreamStatus(
2441 protocol_version(), rst_stream.status())); 2442 protocol_version(), rst_stream.status()));
2442 2443
2443 DCHECK_EQ(expected_length, builder.length()); 2444 DCHECK_EQ(expected_length, builder.length());
2444 return builder.take(); 2445 return builder.take();
2445 } 2446 }
2446 2447
2447 SpdySerializedFrame* SpdyFramer::SerializeSettings( 2448 SpdySerializedFrame* SpdyFramer::SerializeSettings(
2448 const SpdySettingsIR& settings) const { 2449 const SpdySettingsIR& settings) const {
2449 uint8 flags = 0; 2450 uint8_t flags = 0;
2450 2451
2451 if (protocol_version() <= SPDY3) { 2452 if (protocol_version() <= SPDY3) {
2452 if (settings.clear_settings()) { 2453 if (settings.clear_settings()) {
2453 flags |= SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS; 2454 flags |= SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS;
2454 } 2455 }
2455 } else { 2456 } else {
2456 if (settings.is_ack()) { 2457 if (settings.is_ack()) {
2457 flags |= SETTINGS_FLAG_ACK; 2458 flags |= SETTINGS_FLAG_ACK;
2458 } 2459 }
2459 } 2460 }
(...skipping 19 matching lines...) Expand all
2479 builder.WriteUInt32(values->size()); 2480 builder.WriteUInt32(values->size());
2480 } 2481 }
2481 DCHECK_EQ(GetSettingsMinimumSize(), builder.length()); 2482 DCHECK_EQ(GetSettingsMinimumSize(), builder.length());
2482 for (SpdySettingsIR::ValueMap::const_iterator it = values->begin(); 2483 for (SpdySettingsIR::ValueMap::const_iterator it = values->begin();
2483 it != values->end(); 2484 it != values->end();
2484 ++it) { 2485 ++it) {
2485 int setting_id = 2486 int setting_id =
2486 SpdyConstants::SerializeSettingId(protocol_version(), it->first); 2487 SpdyConstants::SerializeSettingId(protocol_version(), it->first);
2487 DCHECK_GE(setting_id, 0); 2488 DCHECK_GE(setting_id, 0);
2488 if (protocol_version() <= SPDY3) { 2489 if (protocol_version() <= SPDY3) {
2489 uint8 setting_flags = 0; 2490 uint8_t setting_flags = 0;
2490 if (it->second.persist_value) { 2491 if (it->second.persist_value) {
2491 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST; 2492 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST;
2492 } 2493 }
2493 if (it->second.persisted) { 2494 if (it->second.persisted) {
2494 setting_flags |= SETTINGS_FLAG_PERSISTED; 2495 setting_flags |= SETTINGS_FLAG_PERSISTED;
2495 } 2496 }
2496 SettingsFlagsAndId flags_and_id(setting_flags, setting_id); 2497 SettingsFlagsAndId flags_and_id(setting_flags, setting_id);
2497 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version()); 2498 uint32_t id_and_flags_wire =
2499 flags_and_id.GetWireFormat(protocol_version());
2498 builder.WriteBytes(&id_and_flags_wire, 4); 2500 builder.WriteBytes(&id_and_flags_wire, 4);
2499 } else { 2501 } else {
2500 builder.WriteUInt16(static_cast<uint16>(setting_id)); 2502 builder.WriteUInt16(static_cast<uint16_t>(setting_id));
2501 } 2503 }
2502 builder.WriteUInt32(it->second.value); 2504 builder.WriteUInt32(it->second.value);
2503 } 2505 }
2504 DCHECK_EQ(size, builder.length()); 2506 DCHECK_EQ(size, builder.length());
2505 return builder.take(); 2507 return builder.take();
2506 } 2508 }
2507 2509
2508 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const { 2510 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const {
2509 SpdyFrameBuilder builder(GetPingSize(), protocol_version()); 2511 SpdyFrameBuilder builder(GetPingSize(), protocol_version());
2510 if (protocol_version() <= SPDY3) { 2512 if (protocol_version() <= SPDY3) {
2511 builder.WriteControlFrameHeader(*this, PING, kNoFlags); 2513 builder.WriteControlFrameHeader(*this, PING, kNoFlags);
2512 builder.WriteUInt32(static_cast<uint32>(ping.id())); 2514 builder.WriteUInt32(static_cast<uint32_t>(ping.id()));
2513 } else { 2515 } else {
2514 uint8 flags = 0; 2516 uint8_t flags = 0;
2515 if (ping.is_ack()) { 2517 if (ping.is_ack()) {
2516 flags |= PING_FLAG_ACK; 2518 flags |= PING_FLAG_ACK;
2517 } 2519 }
2518 builder.BeginNewFrame(*this, PING, flags, 0); 2520 builder.BeginNewFrame(*this, PING, flags, 0);
2519 builder.WriteUInt64(ping.id()); 2521 builder.WriteUInt64(ping.id());
2520 } 2522 }
2521 DCHECK_EQ(GetPingSize(), builder.length()); 2523 DCHECK_EQ(GetPingSize(), builder.length());
2522 return builder.take(); 2524 return builder.take();
2523 } 2525 }
2524 2526
(...skipping 29 matching lines...) Expand all
2554 builder.WriteBytes(goaway.description().data(), 2556 builder.WriteBytes(goaway.description().data(),
2555 goaway.description().size()); 2557 goaway.description().size());
2556 } 2558 }
2557 2559
2558 DCHECK_EQ(expected_length, builder.length()); 2560 DCHECK_EQ(expected_length, builder.length());
2559 return builder.take(); 2561 return builder.take();
2560 } 2562 }
2561 2563
2562 SpdySerializedFrame* SpdyFramer::SerializeHeaders( 2564 SpdySerializedFrame* SpdyFramer::SerializeHeaders(
2563 const SpdyHeadersIR& headers) { 2565 const SpdyHeadersIR& headers) {
2564 uint8 flags = 0; 2566 uint8_t flags = 0;
2565 if (headers.fin()) { 2567 if (headers.fin()) {
2566 flags |= CONTROL_FLAG_FIN; 2568 flags |= CONTROL_FLAG_FIN;
2567 } 2569 }
2568 if (protocol_version() > SPDY3) { 2570 if (protocol_version() > SPDY3) {
2569 // This will get overwritten if we overflow into a CONTINUATION frame. 2571 // This will get overwritten if we overflow into a CONTINUATION frame.
2570 flags |= HEADERS_FLAG_END_HEADERS; 2572 flags |= HEADERS_FLAG_END_HEADERS;
2571 if (headers.has_priority()) { 2573 if (headers.has_priority()) {
2572 flags |= HEADERS_FLAG_PRIORITY; 2574 flags |= HEADERS_FLAG_PRIORITY;
2573 } 2575 }
2574 if (headers.padded()) { 2576 if (headers.padded()) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const { 2685 SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const {
2684 DCHECK_LT(SPDY3, protocol_version()); 2686 DCHECK_LT(SPDY3, protocol_version());
2685 SpdyFrameBuilder builder(GetBlockedSize(), protocol_version()); 2687 SpdyFrameBuilder builder(GetBlockedSize(), protocol_version());
2686 builder.BeginNewFrame(*this, BLOCKED, kNoFlags, blocked.stream_id()); 2688 builder.BeginNewFrame(*this, BLOCKED, kNoFlags, blocked.stream_id());
2687 return builder.take(); 2689 return builder.take();
2688 } 2690 }
2689 2691
2690 SpdyFrame* SpdyFramer::SerializePushPromise( 2692 SpdyFrame* SpdyFramer::SerializePushPromise(
2691 const SpdyPushPromiseIR& push_promise) { 2693 const SpdyPushPromiseIR& push_promise) {
2692 DCHECK_LT(SPDY3, protocol_version()); 2694 DCHECK_LT(SPDY3, protocol_version());
2693 uint8 flags = 0; 2695 uint8_t flags = 0;
2694 // This will get overwritten if we overflow into a CONTINUATION frame. 2696 // This will get overwritten if we overflow into a CONTINUATION frame.
2695 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE; 2697 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2696 // The size of this frame, including variable-length name-value block. 2698 // The size of this frame, including variable-length name-value block.
2697 size_t size = GetPushPromiseMinimumSize(); 2699 size_t size = GetPushPromiseMinimumSize();
2698 2700
2699 if (push_promise.padded()) { 2701 if (push_promise.padded()) {
2700 flags |= PUSH_PROMISE_FLAG_PADDED; 2702 flags |= PUSH_PROMISE_FLAG_PADDED;
2701 size += kPadLengthFieldSize; 2703 size += kPadLengthFieldSize;
2702 size += push_promise.padding_payload_len(); 2704 size += push_promise.padding_payload_len();
2703 } 2705 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2755 2757
2756 return builder.take(); 2758 return builder.take();
2757 } 2759 }
2758 2760
2759 // TODO(jgraettinger): This implementation is incorrect. The continuation 2761 // TODO(jgraettinger): This implementation is incorrect. The continuation
2760 // frame continues a previously-begun HPACK encoding; it doesn't begin a 2762 // frame continues a previously-begun HPACK encoding; it doesn't begin a
2761 // new one. Figure out whether it makes sense to keep SerializeContinuation(). 2763 // new one. Figure out whether it makes sense to keep SerializeContinuation().
2762 SpdyFrame* SpdyFramer::SerializeContinuation( 2764 SpdyFrame* SpdyFramer::SerializeContinuation(
2763 const SpdyContinuationIR& continuation) { 2765 const SpdyContinuationIR& continuation) {
2764 CHECK_LT(SPDY3, protocol_version()); 2766 CHECK_LT(SPDY3, protocol_version());
2765 uint8 flags = 0; 2767 uint8_t flags = 0;
2766 if (continuation.end_headers()) { 2768 if (continuation.end_headers()) {
2767 flags |= HEADERS_FLAG_END_HEADERS; 2769 flags |= HEADERS_FLAG_END_HEADERS;
2768 } 2770 }
2769 2771
2770 // The size of this frame, including variable-length name-value block. 2772 // The size of this frame, including variable-length name-value block.
2771 size_t size = GetContinuationMinimumSize(); 2773 size_t size = GetContinuationMinimumSize();
2772 string hpack_encoding; 2774 string hpack_encoding;
2773 if (enable_compression_) { 2775 if (enable_compression_) {
2774 GetHpackEncoder()->EncodeHeaderSet(continuation.header_block(), 2776 GetHpackEncoder()->EncodeHeaderSet(continuation.header_block(),
2775 &hpack_encoding); 2777 &hpack_encoding);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 size_t payload_size = kMaxControlFrameSize - GetContinuationMinimumSize(); 2908 size_t payload_size = kMaxControlFrameSize - GetContinuationMinimumSize();
2907 // This is ceiling(overflow/payload_size) using integer arithmetics. 2909 // This is ceiling(overflow/payload_size) using integer arithmetics.
2908 return (overflow - 1) / payload_size + 1; 2910 return (overflow - 1) / payload_size + 1;
2909 } 2911 }
2910 2912
2911 void SpdyFramer::WritePayloadWithContinuation(SpdyFrameBuilder* builder, 2913 void SpdyFramer::WritePayloadWithContinuation(SpdyFrameBuilder* builder,
2912 const string& hpack_encoding, 2914 const string& hpack_encoding,
2913 SpdyStreamId stream_id, 2915 SpdyStreamId stream_id,
2914 SpdyFrameType type, 2916 SpdyFrameType type,
2915 int padding_payload_len) { 2917 int padding_payload_len) {
2916 uint8 end_flag = 0; 2918 uint8_t end_flag = 0;
2917 uint8 flags = 0; 2919 uint8_t flags = 0;
2918 if (type == HEADERS) { 2920 if (type == HEADERS) {
2919 end_flag = HEADERS_FLAG_END_HEADERS; 2921 end_flag = HEADERS_FLAG_END_HEADERS;
2920 } else if (type == PUSH_PROMISE) { 2922 } else if (type == PUSH_PROMISE) {
2921 end_flag = PUSH_PROMISE_FLAG_END_PUSH_PROMISE; 2923 end_flag = PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2922 } else { 2924 } else {
2923 DLOG(FATAL) << "CONTINUATION frames cannot be used with frame type " 2925 DLOG(FATAL) << "CONTINUATION frames cannot be used with frame type "
2924 << FrameTypeToString(type); 2926 << FrameTypeToString(type);
2925 } 2927 }
2926 2928
2927 // Write all the padding payload and as much of the data payload as possible 2929 // Write all the padding payload and as much of the data payload as possible
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 } 3032 }
3031 3033
3032 HpackDecoder* SpdyFramer::GetHpackDecoder() { 3034 HpackDecoder* SpdyFramer::GetHpackDecoder() {
3033 DCHECK_LT(SPDY3, protocol_version()); 3035 DCHECK_LT(SPDY3, protocol_version());
3034 if (hpack_decoder_.get() == nullptr) { 3036 if (hpack_decoder_.get() == nullptr) {
3035 hpack_decoder_.reset(new HpackDecoder(ObtainHpackHuffmanTable())); 3037 hpack_decoder_.reset(new HpackDecoder(ObtainHpackHuffmanTable()));
3036 } 3038 }
3037 return hpack_decoder_.get(); 3039 return hpack_decoder_.get();
3038 } 3040 }
3039 3041
3040 uint8 SpdyFramer::MapPriorityToWeight(SpdyPriority priority) { 3042 uint8_t SpdyFramer::MapPriorityToWeight(SpdyPriority priority) {
3041 const float kSteps = 255.9f / 7.f; 3043 const float kSteps = 255.9f / 7.f;
3042 return static_cast<uint8>(kSteps * (7.f - priority)); 3044 return static_cast<uint8_t>(kSteps * (7.f - priority));
3043 } 3045 }
3044 3046
3045 SpdyPriority SpdyFramer::MapWeightToPriority(uint8 weight) { 3047 SpdyPriority SpdyFramer::MapWeightToPriority(uint8_t weight) {
3046 const float kSteps = 255.9f / 7.f; 3048 const float kSteps = 255.9f / 7.f;
3047 return static_cast<SpdyPriority>(7.f - weight / kSteps); 3049 return static_cast<SpdyPriority>(7.f - weight / kSteps);
3048 } 3050 }
3049 3051
3050 // Incrementally decompress the control frame's header block, feeding the 3052 // Incrementally decompress the control frame's header block, feeding the
3051 // result to the visitor in chunks. Continue this until the visitor 3053 // result to the visitor in chunks. Continue this until the visitor
3052 // indicates that it cannot process any more data, or (more commonly) we 3054 // indicates that it cannot process any more data, or (more commonly) we
3053 // run out of data to deliver. 3055 // run out of data to deliver.
3054 bool SpdyFramer::IncrementallyDecompressControlFrameHeaderData( 3056 bool SpdyFramer::IncrementallyDecompressControlFrameHeaderData(
3055 SpdyStreamId stream_id, 3057 SpdyStreamId stream_id,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 len -= bytes_to_deliver; 3134 len -= bytes_to_deliver;
3133 if (!read_successfully) { 3135 if (!read_successfully) {
3134 // Assume that the problem was the header block was too large for the 3136 // Assume that the problem was the header block was too large for the
3135 // visitor. 3137 // visitor.
3136 set_error(SPDY_CONTROL_PAYLOAD_TOO_LARGE); 3138 set_error(SPDY_CONTROL_PAYLOAD_TOO_LARGE);
3137 } 3139 }
3138 } 3140 }
3139 return read_successfully; 3141 return read_successfully;
3140 } 3142 }
3141 3143
3142 void SpdyFramer::UpdateHeaderEncoderTableSize(uint32 value) { 3144 void SpdyFramer::UpdateHeaderEncoderTableSize(uint32_t value) {
3143 GetHpackEncoder()->ApplyHeaderTableSizeSetting(value); 3145 GetHpackEncoder()->ApplyHeaderTableSizeSetting(value);
3144 } 3146 }
3145 3147
3146 size_t SpdyFramer::header_encoder_table_size() const { 3148 size_t SpdyFramer::header_encoder_table_size() const {
3147 if (hpack_encoder_ == nullptr) { 3149 if (hpack_encoder_ == nullptr) {
3148 return kDefaultHeaderTableSizeSetting; 3150 return kDefaultHeaderTableSizeSetting;
3149 } else { 3151 } else {
3150 return hpack_encoder_->CurrentHeaderTableSizeSetting(); 3152 return hpack_encoder_->CurrentHeaderTableSizeSetting();
3151 } 3153 }
3152 } 3154 }
3153 3155
3154 void SpdyFramer::SerializeHeaderBlockWithoutCompression( 3156 void SpdyFramer::SerializeHeaderBlockWithoutCompression(
3155 SpdyFrameBuilder* builder, 3157 SpdyFrameBuilder* builder,
3156 const SpdyHeaderBlock& header_block) const { 3158 const SpdyHeaderBlock& header_block) const {
3157 // Serialize number of headers. 3159 // Serialize number of headers.
3158 if (protocol_version() <= SPDY2) { 3160 if (protocol_version() <= SPDY2) {
3159 builder->WriteUInt16(static_cast<uint16>(header_block.size())); 3161 builder->WriteUInt16(static_cast<uint16_t>(header_block.size()));
3160 } else { 3162 } else {
3161 builder->WriteUInt32(header_block.size()); 3163 builder->WriteUInt32(header_block.size());
3162 } 3164 }
3163 3165
3164 // Serialize each header. 3166 // Serialize each header.
3165 for (const auto& header : header_block) { 3167 for (const auto& header : header_block) {
3166 if (protocol_version() <= SPDY2) { 3168 if (protocol_version() <= SPDY2) {
3167 builder->WriteStringPiece16(header.first); 3169 builder->WriteStringPiece16(header.first);
3168 builder->WriteStringPiece16(header.second); 3170 builder->WriteStringPiece16(header.second);
3169 } else { 3171 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3226 #else 3228 #else
3227 WriteHeaderBlockToZ(&frame.header_block(), compressor); 3229 WriteHeaderBlockToZ(&frame.header_block(), compressor);
3228 #endif // defined(USE_SYSTEM_ZLIB) 3230 #endif // defined(USE_SYSTEM_ZLIB)
3229 3231
3230 int compressed_size = compressed_max_size - compressor->avail_out; 3232 int compressed_size = compressed_max_size - compressor->avail_out;
3231 builder->Seek(compressed_size); 3233 builder->Seek(compressed_size);
3232 builder->RewriteLength(*this); 3234 builder->RewriteLength(*this);
3233 } 3235 }
3234 3236
3235 } // namespace net 3237 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698