OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_headers_block_parser.h" | 5 #include "net/spdy/spdy_headers_block_parser.h" |
6 | 6 |
7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 return; | 149 return; |
150 } | 150 } |
151 // Convert from network to host order and return the parsed out integer. | 151 // Convert from network to host order and return the parsed out integer. |
152 if (length_field_size_ == sizeof(uint32_t)) { | 152 if (length_field_size_ == sizeof(uint32_t)) { |
153 *parsed_length = ntohl(*reinterpret_cast<const uint32_t *>(buffer)); | 153 *parsed_length = ntohl(*reinterpret_cast<const uint32_t *>(buffer)); |
154 } else { | 154 } else { |
155 *parsed_length = ntohs(*reinterpret_cast<const uint16_t *>(buffer)); | 155 *parsed_length = ntohs(*reinterpret_cast<const uint16_t *>(buffer)); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 void SpdyHeadersBlockParser::Reset() { | |
160 { | |
161 SpdyPinnableBufferPiece empty; | |
162 headers_block_prefix_.Swap(&empty); | |
163 } | |
164 { | |
165 SpdyPinnableBufferPiece empty; | |
166 key_.Swap(&empty); | |
167 } | |
168 error_ = OK; | |
169 state_ = READING_HEADER_BLOCK_LEN; | |
170 stream_id_ = 0; | |
171 total_bytes_received_ = 0; | |
172 } | |
173 | |
174 size_t SpdyHeadersBlockParser::LengthFieldSizeForVersion( | 159 size_t SpdyHeadersBlockParser::LengthFieldSizeForVersion( |
175 SpdyMajorVersion spdy_version) { | 160 SpdyMajorVersion spdy_version) { |
176 if (spdy_version < SPDY3) { | 161 if (spdy_version < SPDY3) { |
177 return sizeof(uint16_t); | 162 return sizeof(uint16_t); |
178 } | 163 } |
179 return sizeof(uint32_t); | 164 return sizeof(uint32_t); |
180 } | 165 } |
181 | 166 |
182 size_t SpdyHeadersBlockParser::MaxNumberOfHeadersForVersion( | 167 size_t SpdyHeadersBlockParser::MaxNumberOfHeadersForVersion( |
183 SpdyMajorVersion spdy_version) { | 168 SpdyMajorVersion spdy_version) { |
184 // Account for the length of the header block field. | 169 // Account for the length of the header block field. |
185 size_t max_bytes_for_headers = | 170 size_t max_bytes_for_headers = |
186 kMaximumFieldLength - LengthFieldSizeForVersion(spdy_version); | 171 kMaximumFieldLength - LengthFieldSizeForVersion(spdy_version); |
187 | 172 |
188 // A minimal size header is twice the length field size (and has a | 173 // A minimal size header is twice the length field size (and has a |
189 // zero-lengthed key and a zero-lengthed value). | 174 // zero-lengthed key and a zero-lengthed value). |
190 return max_bytes_for_headers / (2 * LengthFieldSizeForVersion(spdy_version)); | 175 return max_bytes_for_headers / (2 * LengthFieldSizeForVersion(spdy_version)); |
191 } | 176 } |
192 | 177 |
193 } // namespace net | 178 } // namespace net |
OLD | NEW |