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

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

Issue 246013002: SPDY: Headers & Push-Promise now use Continuations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase only Created 6 years, 8 months 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 | Annotate | Revision Log
« 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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't
6 // constantly adding and subtracting header sizes; this is ugly and error- 6 // constantly adding and subtracting header sizes; this is ugly and error-
7 // prone. 7 // prone.
8 8
9 #include "net/spdy/spdy_framer.h" 9 #include "net/spdy/spdy_framer.h"
10 10
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 current_frame_type_ = DATA; 159 current_frame_type_ = DATA;
160 current_frame_flags_ = 0; 160 current_frame_flags_ = 0;
161 current_frame_length_ = 0; 161 current_frame_length_ = 0;
162 current_frame_stream_id_ = kInvalidStream; 162 current_frame_stream_id_ = kInvalidStream;
163 settings_scratch_.Reset(); 163 settings_scratch_.Reset();
164 remaining_padding_payload_length_ = 0; 164 remaining_padding_payload_length_ = 0;
165 remaining_padding_length_fields_ = 0; 165 remaining_padding_length_fields_ = 0;
166 } 166 }
167 167
168 size_t SpdyFramer::GetDataFrameMinimumSize() const { 168 size_t SpdyFramer::GetDataFrameMinimumSize() const {
169 // Size, in bytes, of the data frame header. Future versions of SPDY 169 return SpdyConstants::GetDataFrameMinimumSize();
170 // will likely vary this, so we allow for the flexibility of a function call
171 // for this value as opposed to a constant.
172 return 8;
173 } 170 }
174 171
175 // Size, in bytes, of the control frame header. 172 // Size, in bytes, of the control frame header.
176 size_t SpdyFramer::GetControlFrameHeaderSize() const { 173 size_t SpdyFramer::GetControlFrameHeaderSize() const {
177 switch (protocol_version()) { 174 return SpdyConstants::GetControlFrameHeaderSize(protocol_version());
178 case SPDY2:
179 case SPDY3:
180 case SPDY4:
181 return 8;
182 }
183 LOG(DFATAL) << "Unhandled SPDY version.";
184 return 0;
185 } 175 }
186 176
187 size_t SpdyFramer::GetSynStreamMinimumSize() const { 177 size_t SpdyFramer::GetSynStreamMinimumSize() const {
188 // Size, in bytes, of a SYN_STREAM frame not including the variable-length 178 // Size, in bytes, of a SYN_STREAM frame not including the variable-length
189 // name-value block. 179 // name-value block.
190 if (protocol_version() <= SPDY3) { 180 if (protocol_version() <= SPDY3) {
191 // Calculated as: 181 // Calculated as:
192 // control frame header + 2 * 4 (stream IDs) + 1 (priority) 182 // control frame header + 2 * 4 (stream IDs) + 1 (priority)
193 // + 1 (unused, was credential slot) 183 // + 1 (unused, was credential slot)
194 return GetControlFrameHeaderSize() + 10; 184 return GetControlFrameHeaderSize() + 10;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // Size, in bytes, of a CONTINUATION frame not including the variable-length 309 // Size, in bytes, of a CONTINUATION frame not including the variable-length
320 // headers fragments. 310 // headers fragments.
321 return GetControlFrameHeaderSize(); 311 return GetControlFrameHeaderSize();
322 } 312 }
323 313
324 size_t SpdyFramer::GetFrameMinimumSize() const { 314 size_t SpdyFramer::GetFrameMinimumSize() const {
325 return std::min(GetDataFrameMinimumSize(), GetControlFrameHeaderSize()); 315 return std::min(GetDataFrameMinimumSize(), GetControlFrameHeaderSize());
326 } 316 }
327 317
328 size_t SpdyFramer::GetFrameMaximumSize() const { 318 size_t SpdyFramer::GetFrameMaximumSize() const {
329 if (protocol_version() <= SPDY3) { 319 return SpdyConstants::GetFrameMaximumSize(protocol_version());
330 // 24-bit length field plus eight-byte frame header.
331 return ((1<<24) - 1) + 8;
332 } else {
333 // 14-bit length field.
334 return (1<<14) - 1;
335 }
336 } 320 }
337 321
338 size_t SpdyFramer::GetDataFrameMaximumPayload() const { 322 size_t SpdyFramer::GetDataFrameMaximumPayload() const {
339 return GetFrameMaximumSize() - GetDataFrameMinimumSize(); 323 return GetFrameMaximumSize() - GetDataFrameMinimumSize();
340 } 324 }
341 325
326 size_t SpdyFramer::GetPrefixLength(SpdyFrameType type) const {
327 return SpdyConstants::GetPrefixLength(type, protocol_version());
328 }
329
342 const char* SpdyFramer::StateToString(int state) { 330 const char* SpdyFramer::StateToString(int state) {
343 switch (state) { 331 switch (state) {
344 case SPDY_ERROR: 332 case SPDY_ERROR:
345 return "ERROR"; 333 return "ERROR";
346 case SPDY_AUTO_RESET: 334 case SPDY_AUTO_RESET:
347 return "AUTO_RESET"; 335 return "AUTO_RESET";
348 case SPDY_RESET: 336 case SPDY_RESET:
349 return "RESET"; 337 return "RESET";
350 case SPDY_READING_COMMON_HEADER: 338 case SPDY_READING_COMMON_HEADER:
351 return "READING_COMMON_HEADER"; 339 return "READING_COMMON_HEADER";
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 DCHECK_LT(SPDY3, protocol_version()); 1582 DCHECK_LT(SPDY3, protocol_version());
1595 DCHECK_EQ(0u, remaining_data_length_); 1583 DCHECK_EQ(0u, remaining_data_length_);
1596 1584
1597 const SpdyNameValueBlock& block = hpack_decoder_.decoded_block(); 1585 const SpdyNameValueBlock& block = hpack_decoder_.decoded_block();
1598 if (block.empty()) { 1586 if (block.empty()) {
1599 // Special-case this to make tests happy. 1587 // Special-case this to make tests happy.
1600 ProcessControlFrameHeaderBlock(NULL, 0, false); 1588 ProcessControlFrameHeaderBlock(NULL, 0, false);
1601 return; 1589 return;
1602 } 1590 }
1603 SpdyFrameBuilder builder( 1591 SpdyFrameBuilder builder(
1604 GetSerializedLength(protocol_version(), &block)); 1592 GetSerializedLength(protocol_version(), &block),
1593 SPDY3);
1605 1594
1606 SerializeNameValueBlockWithoutCompression(&builder, block); 1595 SerializeNameValueBlockWithoutCompression(&builder, block);
1607 scoped_ptr<SpdyFrame> frame(builder.take()); 1596 scoped_ptr<SpdyFrame> frame(builder.take());
1608 1597
1609 remaining_data_length_ = frame->size(); 1598 remaining_data_length_ = frame->size();
1610 ProcessControlFrameHeaderBlock(frame->data(), frame->size(), false); 1599 ProcessControlFrameHeaderBlock(frame->data(), frame->size(), false);
1611 } 1600 }
1612 1601
1613 bool SpdyFramer::ProcessSetting(const char* data) { 1602 bool SpdyFramer::ProcessSetting(const char* data) {
1614 int id_field; 1603 int id_field;
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 ++num_padding_fields; 2013 ++num_padding_fields;
2025 } 2014 }
2026 if (data_ir.pad_high()) { 2015 if (data_ir.pad_high()) {
2027 flags |= DATA_FLAG_PAD_HIGH; 2016 flags |= DATA_FLAG_PAD_HIGH;
2028 ++num_padding_fields; 2017 ++num_padding_fields;
2029 } 2018 }
2030 2019
2031 const size_t size_with_padding = num_padding_fields + 2020 const size_t size_with_padding = num_padding_fields +
2032 data_ir.data().length() + data_ir.padding_payload_len() + 2021 data_ir.data().length() + data_ir.padding_payload_len() +
2033 GetDataFrameMinimumSize(); 2022 GetDataFrameMinimumSize();
2034 SpdyFrameBuilder builder(size_with_padding); 2023 SpdyFrameBuilder builder(size_with_padding, protocol_version());
2035 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags); 2024 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags);
2036 if (data_ir.pad_high()) { 2025 if (data_ir.pad_high()) {
2037 builder.WriteUInt8(data_ir.padding_payload_len() >> 8); 2026 builder.WriteUInt8(data_ir.padding_payload_len() >> 8);
2038 } 2027 }
2039 if (data_ir.pad_low()) { 2028 if (data_ir.pad_low()) {
2040 builder.WriteUInt8(data_ir.padding_payload_len() & 0xff); 2029 builder.WriteUInt8(data_ir.padding_payload_len() & 0xff);
2041 } 2030 }
2042 builder.WriteBytes(data_ir.data().data(), data_ir.data().length()); 2031 builder.WriteBytes(data_ir.data().data(), data_ir.data().length());
2043 if (data_ir.padding_payload_len() > 0) { 2032 if (data_ir.padding_payload_len() > 0) {
2044 string padding = string(data_ir.padding_payload_len(), '0'); 2033 string padding = string(data_ir.padding_payload_len(), '0');
2045 builder.WriteBytes(padding.data(), padding.length()); 2034 builder.WriteBytes(padding.data(), padding.length());
2046 } 2035 }
2047 DCHECK_EQ(size_with_padding, builder.length()); 2036 DCHECK_EQ(size_with_padding, builder.length());
2048 return builder.take(); 2037 return builder.take();
2049 } else { 2038 } else {
2050 const size_t size = GetDataFrameMinimumSize() + data_ir.data().length(); 2039 const size_t size = GetDataFrameMinimumSize() + data_ir.data().length();
2051 SpdyFrameBuilder builder(size); 2040 SpdyFrameBuilder builder(size, protocol_version());
2052 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags); 2041 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags);
2053 builder.WriteBytes(data_ir.data().data(), data_ir.data().length()); 2042 builder.WriteBytes(data_ir.data().data(), data_ir.data().length());
2054 DCHECK_EQ(size, builder.length()); 2043 DCHECK_EQ(size, builder.length());
2055 return builder.take(); 2044 return builder.take();
2056 } 2045 }
2057 } 2046 }
2058 2047
2059 SpdySerializedFrame* SpdyFramer::SerializeDataFrameHeaderWithPaddingLengthField( 2048 SpdySerializedFrame* SpdyFramer::SerializeDataFrameHeaderWithPaddingLengthField(
2060 const SpdyDataIR& data_ir) const { 2049 const SpdyDataIR& data_ir) const {
2061 uint8 flags = DATA_FLAG_NONE; 2050 uint8 flags = DATA_FLAG_NONE;
2062 if (data_ir.fin()) { 2051 if (data_ir.fin()) {
2063 flags = DATA_FLAG_FIN; 2052 flags = DATA_FLAG_FIN;
2064 } 2053 }
2065 2054
2066 size_t frame_size = GetDataFrameMinimumSize(); 2055 size_t frame_size = GetDataFrameMinimumSize();
2067 size_t num_padding_fields = 0; 2056 size_t num_padding_fields = 0;
2068 if (protocol_version() > SPDY3) { 2057 if (protocol_version() > SPDY3) {
2069 if (data_ir.pad_low()) { 2058 if (data_ir.pad_low()) {
2070 flags |= DATA_FLAG_PAD_LOW; 2059 flags |= DATA_FLAG_PAD_LOW;
2071 ++num_padding_fields; 2060 ++num_padding_fields;
2072 } 2061 }
2073 if (data_ir.pad_high()) { 2062 if (data_ir.pad_high()) {
2074 flags |= DATA_FLAG_PAD_HIGH; 2063 flags |= DATA_FLAG_PAD_HIGH;
2075 ++num_padding_fields; 2064 ++num_padding_fields;
2076 } 2065 }
2077 frame_size += num_padding_fields; 2066 frame_size += num_padding_fields;
2078 } 2067 }
2079 2068
2080 SpdyFrameBuilder builder(frame_size); 2069 SpdyFrameBuilder builder(frame_size, protocol_version());
2081 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags); 2070 builder.WriteDataFrameHeader(*this, data_ir.stream_id(), flags);
2082 if (protocol_version() > SPDY3) { 2071 if (protocol_version() > SPDY3) {
2083 if (data_ir.pad_high()) { 2072 if (data_ir.pad_high()) {
2084 builder.WriteUInt8(data_ir.padding_payload_len() >> 8); 2073 builder.WriteUInt8(data_ir.padding_payload_len() >> 8);
2085 } 2074 }
2086 if (data_ir.pad_low()) { 2075 if (data_ir.pad_low()) {
2087 builder.WriteUInt8(data_ir.padding_payload_len() & 0xff); 2076 builder.WriteUInt8(data_ir.padding_payload_len() & 0xff);
2088 } 2077 }
2089 builder.OverwriteLength(*this, num_padding_fields + 2078 builder.OverwriteLength(*this, num_padding_fields +
2090 data_ir.data().length() + data_ir.padding_payload_len()); 2079 data_ir.data().length() + data_ir.padding_payload_len());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 2113
2125 string hpack_encoding; 2114 string hpack_encoding;
2126 if (protocol_version() > SPDY3) { 2115 if (protocol_version() > SPDY3) {
2127 hpack_encoder_.EncodeHeaderSet(syn_stream.name_value_block(), 2116 hpack_encoder_.EncodeHeaderSet(syn_stream.name_value_block(),
2128 &hpack_encoding); 2117 &hpack_encoding);
2129 size += hpack_encoding.size(); 2118 size += hpack_encoding.size();
2130 } else { 2119 } else {
2131 size += GetSerializedLength(syn_stream.name_value_block()); 2120 size += GetSerializedLength(syn_stream.name_value_block());
2132 } 2121 }
2133 2122
2134 SpdyFrameBuilder builder(size); 2123 SpdyFrameBuilder builder(size, protocol_version());
2135 if (protocol_version() <= SPDY3) { 2124 if (protocol_version() <= SPDY3) {
2136 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags); 2125 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags);
2137 builder.WriteUInt32(syn_stream.stream_id()); 2126 builder.WriteUInt32(syn_stream.stream_id());
2138 builder.WriteUInt32(syn_stream.associated_to_stream_id()); 2127 builder.WriteUInt32(syn_stream.associated_to_stream_id());
2139 builder.WriteUInt8(priority << ((protocol_version() <= SPDY2) ? 6 : 5)); 2128 builder.WriteUInt8(priority << ((protocol_version() <= SPDY2) ? 6 : 5));
2140 builder.WriteUInt8(0); // Unused byte where credential slot used to be. 2129 builder.WriteUInt8(0); // Unused byte where credential slot used to be.
2141 } else { 2130 } else {
2142 builder.WriteFramePrefix(*this, 2131 builder.BeginNewFrame(*this,
2143 HEADERS, 2132 HEADERS,
2144 flags, 2133 flags,
2145 syn_stream.stream_id()); 2134 syn_stream.stream_id());
2146 builder.WriteUInt32(priority); 2135 builder.WriteUInt32(priority);
2147 } 2136 }
2148 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length()); 2137 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length());
2149 if (protocol_version() > SPDY3) { 2138 if (protocol_version() > SPDY3) {
2150 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2139 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
2151 } else { 2140 } else {
2152 SerializeNameValueBlock(&builder, syn_stream); 2141 SerializeNameValueBlock(&builder, syn_stream);
2153 } 2142 }
2154 2143
2155 if (debug_visitor_) { 2144 if (debug_visitor_) {
(...skipping 28 matching lines...) Expand all
2184 2173
2185 string hpack_encoding; 2174 string hpack_encoding;
2186 if (protocol_version() > SPDY3) { 2175 if (protocol_version() > SPDY3) {
2187 hpack_encoder_.EncodeHeaderSet(syn_reply.name_value_block(), 2176 hpack_encoder_.EncodeHeaderSet(syn_reply.name_value_block(),
2188 &hpack_encoding); 2177 &hpack_encoding);
2189 size += hpack_encoding.size(); 2178 size += hpack_encoding.size();
2190 } else { 2179 } else {
2191 size += GetSerializedLength(syn_reply.name_value_block()); 2180 size += GetSerializedLength(syn_reply.name_value_block());
2192 } 2181 }
2193 2182
2194 SpdyFrameBuilder builder(size); 2183 SpdyFrameBuilder builder(size, protocol_version());
2195 if (protocol_version() <= SPDY3) { 2184 if (protocol_version() <= SPDY3) {
2196 builder.WriteControlFrameHeader(*this, SYN_REPLY, flags); 2185 builder.WriteControlFrameHeader(*this, SYN_REPLY, flags);
2197 builder.WriteUInt32(syn_reply.stream_id()); 2186 builder.WriteUInt32(syn_reply.stream_id());
2198 } else { 2187 } else {
2199 builder.WriteFramePrefix(*this, 2188 builder.BeginNewFrame(*this,
2200 HEADERS, 2189 HEADERS,
2201 flags, 2190 flags,
2202 syn_reply.stream_id()); 2191 syn_reply.stream_id());
2203 } 2192 }
2204 if (protocol_version() < SPDY3) { 2193 if (protocol_version() < SPDY3) {
2205 builder.WriteUInt16(0); // Unused. 2194 builder.WriteUInt16(0); // Unused.
2206 } 2195 }
2207 DCHECK_EQ(GetSynReplyMinimumSize(), builder.length()); 2196 DCHECK_EQ(GetSynReplyMinimumSize(), builder.length());
2208 if (protocol_version() > SPDY3) { 2197 if (protocol_version() > SPDY3) {
2209 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2198 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
2210 } else { 2199 } else {
2211 SerializeNameValueBlock(&builder, syn_reply); 2200 SerializeNameValueBlock(&builder, syn_reply);
2212 } 2201 }
(...skipping 16 matching lines...) Expand all
2229 const SpdyRstStreamIR& rst_stream) const { 2218 const SpdyRstStreamIR& rst_stream) const {
2230 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM 2219 // TODO(jgraettinger): For now, Chromium will support parsing RST_STREAM
2231 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2, 2220 // payloads, but will not emit them. SPDY4 is used for draft HTTP/2,
2232 // which doesn't currently include RST_STREAM payloads. GFE flags have been 2221 // which doesn't currently include RST_STREAM payloads. GFE flags have been
2233 // commented but left in place to simplify future patching. 2222 // commented but left in place to simplify future patching.
2234 // Compute the output buffer size, taking opaque data into account. 2223 // Compute the output buffer size, taking opaque data into account.
2235 uint16 expected_length = GetRstStreamMinimumSize(); 2224 uint16 expected_length = GetRstStreamMinimumSize();
2236 if (protocol_version() > SPDY3) { 2225 if (protocol_version() > SPDY3) {
2237 expected_length += rst_stream.description().size(); 2226 expected_length += rst_stream.description().size();
2238 } 2227 }
2239 SpdyFrameBuilder builder(expected_length); 2228 SpdyFrameBuilder builder(expected_length, protocol_version());
2240 2229
2241 // Serialize the RST_STREAM frame. 2230 // Serialize the RST_STREAM frame.
2242 if (protocol_version() <= SPDY3) { 2231 if (protocol_version() <= SPDY3) {
2243 builder.WriteControlFrameHeader(*this, RST_STREAM, 0); 2232 builder.WriteControlFrameHeader(*this, RST_STREAM, 0);
2244 builder.WriteUInt32(rst_stream.stream_id()); 2233 builder.WriteUInt32(rst_stream.stream_id());
2245 } else { 2234 } else {
2246 builder.WriteFramePrefix(*this, RST_STREAM, 0, rst_stream.stream_id()); 2235 builder.BeginNewFrame(*this, RST_STREAM, 0, rst_stream.stream_id());
2247 } 2236 }
2248 2237
2249 builder.WriteUInt32(rst_stream.status()); 2238 builder.WriteUInt32(rst_stream.status());
2250 2239
2251 // In SPDY4 and up, RST_STREAM frames may also specify opaque data. 2240 // In SPDY4 and up, RST_STREAM frames may also specify opaque data.
2252 if (protocol_version() > SPDY3 && rst_stream.description().size() > 0) { 2241 if (protocol_version() > SPDY3 && rst_stream.description().size() > 0) {
2253 builder.WriteBytes(rst_stream.description().data(), 2242 builder.WriteBytes(rst_stream.description().data(),
2254 rst_stream.description().size()); 2243 rst_stream.description().size());
2255 } 2244 }
2256 2245
(...skipping 13 matching lines...) Expand all
2270 if (settings.is_ack()) { 2259 if (settings.is_ack()) {
2271 flags |= SETTINGS_FLAG_ACK; 2260 flags |= SETTINGS_FLAG_ACK;
2272 } 2261 }
2273 } 2262 }
2274 const SpdySettingsIR::ValueMap* values = &(settings.values()); 2263 const SpdySettingsIR::ValueMap* values = &(settings.values());
2275 2264
2276 size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5); 2265 size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5);
2277 // Size, in bytes, of this SETTINGS frame. 2266 // Size, in bytes, of this SETTINGS frame.
2278 const size_t size = GetSettingsMinimumSize() + 2267 const size_t size = GetSettingsMinimumSize() +
2279 (values->size() * setting_size); 2268 (values->size() * setting_size);
2280 SpdyFrameBuilder builder(size); 2269 SpdyFrameBuilder builder(size, protocol_version());
2281 if (protocol_version() <= SPDY3) { 2270 if (protocol_version() <= SPDY3) {
2282 builder.WriteControlFrameHeader(*this, SETTINGS, flags); 2271 builder.WriteControlFrameHeader(*this, SETTINGS, flags);
2283 } else { 2272 } else {
2284 builder.WriteFramePrefix(*this, SETTINGS, flags, 0); 2273 builder.BeginNewFrame(*this, SETTINGS, flags, 0);
2285 } 2274 }
2286 2275
2287 // If this is an ACK, payload should be empty. 2276 // If this is an ACK, payload should be empty.
2288 if (protocol_version() > SPDY3 && settings.is_ack()) { 2277 if (protocol_version() > SPDY3 && settings.is_ack()) {
2289 return builder.take(); 2278 return builder.take();
2290 } 2279 }
2291 2280
2292 if (protocol_version() <= SPDY3) { 2281 if (protocol_version() <= SPDY3) {
2293 builder.WriteUInt32(values->size()); 2282 builder.WriteUInt32(values->size());
2294 } 2283 }
(...skipping 17 matching lines...) Expand all
2312 } else { 2301 } else {
2313 builder.WriteUInt8(SpdyConstants::SerializeSettingId(protocol_version(), 2302 builder.WriteUInt8(SpdyConstants::SerializeSettingId(protocol_version(),
2314 it->first)); 2303 it->first));
2315 } 2304 }
2316 builder.WriteUInt32(it->second.value); 2305 builder.WriteUInt32(it->second.value);
2317 } 2306 }
2318 DCHECK_EQ(size, builder.length()); 2307 DCHECK_EQ(size, builder.length());
2319 return builder.take(); 2308 return builder.take();
2320 } 2309 }
2321 2310
2322 SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const {
2323 DCHECK_LT(SPDY3, protocol_version());
2324 SpdyFrameBuilder builder(GetBlockedSize());
2325 builder.WriteFramePrefix(*this, BLOCKED, kNoFlags, blocked.stream_id());
2326 return builder.take();
2327 }
2328
2329 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const { 2311 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const {
2330 SpdyFrameBuilder builder(GetPingSize()); 2312 SpdyFrameBuilder builder(GetPingSize(), protocol_version());
2331 if (protocol_version() <= SPDY3) { 2313 if (protocol_version() <= SPDY3) {
2332 builder.WriteControlFrameHeader(*this, PING, kNoFlags); 2314 builder.WriteControlFrameHeader(*this, PING, kNoFlags);
2333 builder.WriteUInt32(static_cast<uint32>(ping.id())); 2315 builder.WriteUInt32(static_cast<uint32>(ping.id()));
2334 } else { 2316 } else {
2335 uint8 flags = 0; 2317 uint8 flags = 0;
2336 if (ping.is_ack()) { 2318 if (ping.is_ack()) {
2337 flags |= PING_FLAG_ACK; 2319 flags |= PING_FLAG_ACK;
2338 } 2320 }
2339 builder.WriteFramePrefix(*this, PING, flags, 0); 2321 builder.BeginNewFrame(*this, PING, flags, 0);
2340 builder.WriteUInt64(ping.id()); 2322 builder.WriteUInt64(ping.id());
2341 } 2323 }
2342 DCHECK_EQ(GetPingSize(), builder.length()); 2324 DCHECK_EQ(GetPingSize(), builder.length());
2343 return builder.take(); 2325 return builder.take();
2344 } 2326 }
2345 2327
2346 SpdySerializedFrame* SpdyFramer::SerializeGoAway( 2328 SpdySerializedFrame* SpdyFramer::SerializeGoAway(
2347 const SpdyGoAwayIR& goaway) const { 2329 const SpdyGoAwayIR& goaway) const {
2348 2330
2349 // Compute the output buffer size, take opaque data into account. 2331 // Compute the output buffer size, take opaque data into account.
2350 uint16 expected_length = GetGoAwayMinimumSize(); 2332 uint16 expected_length = GetGoAwayMinimumSize();
2351 if (protocol_version() > SPDY3) { 2333 if (protocol_version() > SPDY3) {
2352 expected_length += goaway.description().size(); 2334 expected_length += goaway.description().size();
2353 } 2335 }
2354 SpdyFrameBuilder builder(expected_length); 2336 SpdyFrameBuilder builder(expected_length, protocol_version());
2355 2337
2356 // Serialize the GOAWAY frame. 2338 // Serialize the GOAWAY frame.
2357 if (protocol_version() <= SPDY3) { 2339 if (protocol_version() <= SPDY3) {
2358 builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags); 2340 builder.WriteControlFrameHeader(*this, GOAWAY, kNoFlags);
2359 } else { 2341 } else {
2360 builder.WriteFramePrefix(*this, GOAWAY, 0, 0); 2342 builder.BeginNewFrame(*this, GOAWAY, 0, 0);
2361 } 2343 }
2362 2344
2363 // GOAWAY frames specify the last good stream id for all SPDY versions. 2345 // GOAWAY frames specify the last good stream id for all SPDY versions.
2364 builder.WriteUInt32(goaway.last_good_stream_id()); 2346 builder.WriteUInt32(goaway.last_good_stream_id());
2365 2347
2366 // In SPDY3 and up, GOAWAY frames also specify the error status code. 2348 // In SPDY3 and up, GOAWAY frames also specify the error status code.
2367 if (protocol_version() >= SPDY3) { 2349 if (protocol_version() >= SPDY3) {
2368 builder.WriteUInt32(goaway.status()); 2350 builder.WriteUInt32(goaway.status());
2369 } 2351 }
2370 2352
2371 // In SPDY4 and up, GOAWAY frames may also specify opaque data. 2353 // In SPDY4 and up, GOAWAY frames may also specify opaque data.
2372 if ((protocol_version() > SPDY3) && (goaway.description().size() > 0)) { 2354 if ((protocol_version() > SPDY3) && (goaway.description().size() > 0)) {
2373 builder.WriteBytes(goaway.description().data(), 2355 builder.WriteBytes(goaway.description().data(),
2374 goaway.description().size()); 2356 goaway.description().size());
2375 } 2357 }
2376 2358
2377 DCHECK_EQ(expected_length, builder.length()); 2359 DCHECK_EQ(expected_length, builder.length());
2378 return builder.take(); 2360 return builder.take();
2379 } 2361 }
2380 2362
2381 SpdySerializedFrame* SpdyFramer::SerializeHeaders( 2363 SpdySerializedFrame* SpdyFramer::SerializeHeaders(
2382 const SpdyHeadersIR& headers) { 2364 const SpdyHeadersIR& headers) {
2383 uint8 flags = 0; 2365 uint8 flags = 0;
2384 if (headers.fin()) { 2366 if (headers.fin()) {
2385 flags |= CONTROL_FLAG_FIN; 2367 flags |= CONTROL_FLAG_FIN;
2386 } 2368 }
2387 if (protocol_version() > SPDY3) { 2369 if (protocol_version() > SPDY3) {
2370 // TODO(mlavan): If we overflow into a CONTINUATION frame, this will
2371 // get overwritten below, so we should probably just get rid of the
2372 // end_headers field.
2388 if (headers.end_headers()) { 2373 if (headers.end_headers()) {
2389 flags |= HEADERS_FLAG_END_HEADERS; 2374 flags |= HEADERS_FLAG_END_HEADERS;
2390 } 2375 }
2391 if (headers.has_priority()) { 2376 if (headers.has_priority()) {
2392 flags |= HEADERS_FLAG_PRIORITY; 2377 flags |= HEADERS_FLAG_PRIORITY;
2393 } 2378 }
2394 } 2379 }
2395 2380
2396 // The size of this frame, including variable-length name-value block. 2381 // The size of this frame, including variable-length name-value block.
2397 size_t size = GetHeadersMinimumSize(); 2382 size_t size = GetHeadersMinimumSize();
2398 2383
2399 uint32 priority = headers.priority(); 2384 uint32 priority = headers.priority();
2400 if (headers.has_priority()) { 2385 if (headers.has_priority()) {
2401 if (priority > GetLowestPriority()) { 2386 if (priority > GetLowestPriority()) {
2402 DLOG(DFATAL) << "Priority out-of-bounds."; 2387 DLOG(DFATAL) << "Priority out-of-bounds.";
2403 priority = GetLowestPriority(); 2388 priority = GetLowestPriority();
2404 } 2389 }
2405 size += 4; 2390 size += 4;
2406 } 2391 }
2407 2392
2408 string hpack_encoding; 2393 string hpack_encoding;
2409 if (protocol_version() > SPDY3) { 2394 if (protocol_version() > SPDY3) {
2410 hpack_encoder_.EncodeHeaderSet(headers.name_value_block(), &hpack_encoding); 2395 hpack_encoder_.EncodeHeaderSet(headers.name_value_block(), &hpack_encoding);
2411 size += hpack_encoding.size(); 2396 size += hpack_encoding.size();
2397 if (size > GetControlFrameBufferMaxSize()) {
2398 size += GetNumberRequiredContinuationFrames(size) *
2399 GetContinuationMinimumSize();
2400 flags &= ~HEADERS_FLAG_END_HEADERS;
2401 }
2412 } else { 2402 } else {
2413 size += GetSerializedLength(headers.name_value_block()); 2403 size += GetSerializedLength(headers.name_value_block());
2414 } 2404 }
2415 2405
2416 SpdyFrameBuilder builder(size); 2406 SpdyFrameBuilder builder(size, protocol_version());
2417 if (protocol_version() <= SPDY3) { 2407 if (protocol_version() <= SPDY3) {
2418 builder.WriteControlFrameHeader(*this, HEADERS, flags); 2408 builder.WriteControlFrameHeader(*this, HEADERS, flags);
2419 builder.WriteUInt32(headers.stream_id()); 2409 builder.WriteUInt32(headers.stream_id());
2420 } else { 2410 } else {
2421 builder.WriteFramePrefix(*this, 2411 builder.BeginNewFrame(*this,
2422 HEADERS, 2412 HEADERS,
2423 flags, 2413 flags,
2424 headers.stream_id()); 2414 headers.stream_id());
2425 if (headers.has_priority()) { 2415 if (headers.has_priority()) {
2426 builder.WriteUInt32(priority); 2416 builder.WriteUInt32(priority);
2427 } 2417 }
2428 } 2418 }
2429 if (protocol_version() <= SPDY2) { 2419 if (protocol_version() <= SPDY2) {
2430 builder.WriteUInt16(0); // Unused. 2420 builder.WriteUInt16(0); // Unused.
2431 } 2421 }
2432 DCHECK_EQ(GetHeadersMinimumSize(), builder.length()); 2422 DCHECK_EQ(GetHeadersMinimumSize(), builder.length());
2433 2423
2434 if (protocol_version() > SPDY3) { 2424 if (protocol_version() > SPDY3) {
2435 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2425 WritePayloadWithContinuation(&builder,
2426 hpack_encoding,
2427 headers.stream_id(),
2428 HEADERS);
2436 } else { 2429 } else {
2437 SerializeNameValueBlock(&builder, headers); 2430 SerializeNameValueBlock(&builder, headers);
2438 } 2431 }
2439 2432
2440 if (debug_visitor_) { 2433 if (debug_visitor_) {
2441 const size_t payload_len = protocol_version() > SPDY3 ? 2434 const size_t payload_len = protocol_version() > SPDY3 ?
2442 hpack_encoding.size() : 2435 hpack_encoding.size() :
2443 GetSerializedLength(protocol_version(), 2436 GetSerializedLength(protocol_version(),
2444 &(headers.name_value_block())); 2437 &(headers.name_value_block()));
2445 debug_visitor_->OnSendCompressedFrame(headers.stream_id(), 2438 debug_visitor_->OnSendCompressedFrame(headers.stream_id(),
2446 HEADERS, 2439 HEADERS,
2447 payload_len, 2440 payload_len,
2448 builder.length()); 2441 builder.length());
2449 } 2442 }
2450 2443
2451 return builder.take(); 2444 return builder.take();
2452 } 2445 }
2453 2446
2454 SpdySerializedFrame* SpdyFramer::SerializeWindowUpdate( 2447 SpdySerializedFrame* SpdyFramer::SerializeWindowUpdate(
2455 const SpdyWindowUpdateIR& window_update) const { 2448 const SpdyWindowUpdateIR& window_update) const {
2456 SpdyFrameBuilder builder(GetWindowUpdateSize()); 2449 SpdyFrameBuilder builder(GetWindowUpdateSize(), protocol_version());
2457 if (protocol_version() <= SPDY3) { 2450 if (protocol_version() <= SPDY3) {
2458 builder.WriteControlFrameHeader(*this, WINDOW_UPDATE, kNoFlags); 2451 builder.WriteControlFrameHeader(*this, WINDOW_UPDATE, kNoFlags);
2459 builder.WriteUInt32(window_update.stream_id()); 2452 builder.WriteUInt32(window_update.stream_id());
2460 } else { 2453 } else {
2461 builder.WriteFramePrefix(*this, 2454 builder.BeginNewFrame(*this,
2462 WINDOW_UPDATE, 2455 WINDOW_UPDATE,
2463 kNoFlags, 2456 kNoFlags,
2464 window_update.stream_id()); 2457 window_update.stream_id());
2465 } 2458 }
2466 builder.WriteUInt32(window_update.delta()); 2459 builder.WriteUInt32(window_update.delta());
2467 DCHECK_EQ(GetWindowUpdateSize(), builder.length()); 2460 DCHECK_EQ(GetWindowUpdateSize(), builder.length());
2468 return builder.take(); 2461 return builder.take();
2469 } 2462 }
2470 2463
2464 SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const {
2465 DCHECK_LT(SPDY3, protocol_version());
2466 SpdyFrameBuilder builder(GetBlockedSize(), protocol_version());
2467 builder.BeginNewFrame(*this, BLOCKED, kNoFlags, blocked.stream_id());
2468 return builder.take();
2469 }
2470
2471 SpdyFrame* SpdyFramer::SerializePushPromise( 2471 SpdyFrame* SpdyFramer::SerializePushPromise(
2472 const SpdyPushPromiseIR& push_promise) { 2472 const SpdyPushPromiseIR& push_promise) {
2473 DCHECK_LT(SPDY3, protocol_version()); 2473 DCHECK_LT(SPDY3, protocol_version());
2474 uint8 flags = 0; 2474 uint8 flags = 0;
2475 // TODO(mlavan): If we overflow into a CONTINUATION frame, this will
2476 // get overwritten below, so we should probably just get rid of the
2477 // end_push_promise field.
2475 if (push_promise.end_push_promise()) { 2478 if (push_promise.end_push_promise()) {
2476 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE; 2479 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2477 } 2480 }
2478 // The size of this frame, including variable-length name-value block. 2481 // The size of this frame, including variable-length name-value block.
2479 size_t size = GetPushPromiseMinimumSize(); 2482 size_t size = GetPushPromiseMinimumSize();
2480 2483
2481 string hpack_encoding; 2484 string hpack_encoding;
2482 if (protocol_version() > SPDY3) { 2485 if (protocol_version() > SPDY3) {
2483 hpack_encoder_.EncodeHeaderSet(push_promise.name_value_block(), 2486 hpack_encoder_.EncodeHeaderSet(push_promise.name_value_block(),
2484 &hpack_encoding); 2487 &hpack_encoding);
2485 size += hpack_encoding.size(); 2488 size += hpack_encoding.size();
2489 if (size > GetControlFrameBufferMaxSize()) {
2490 size += GetNumberRequiredContinuationFrames(size) *
2491 GetContinuationMinimumSize();
2492 flags &= ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2493 }
2486 } else { 2494 } else {
2487 size += GetSerializedLength(push_promise.name_value_block()); 2495 size += GetSerializedLength(push_promise.name_value_block());
2488 } 2496 }
2489 2497
2490 SpdyFrameBuilder builder(size); 2498 SpdyFrameBuilder builder(size, protocol_version());
2491 builder.WriteFramePrefix(*this, PUSH_PROMISE, flags, 2499 builder.BeginNewFrame(*this,
2492 push_promise.stream_id()); 2500 PUSH_PROMISE,
2501 flags,
2502 push_promise.stream_id());
2493 builder.WriteUInt32(push_promise.promised_stream_id()); 2503 builder.WriteUInt32(push_promise.promised_stream_id());
2494 DCHECK_EQ(GetPushPromiseMinimumSize(), builder.length()); 2504 DCHECK_EQ(GetPushPromiseMinimumSize(), builder.length());
2495 2505
2496 if (protocol_version() > SPDY3) { 2506 if (protocol_version() > SPDY3) {
2497 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2507 WritePayloadWithContinuation(&builder,
2508 hpack_encoding,
2509 push_promise.stream_id(),
2510 PUSH_PROMISE);
2498 } else { 2511 } else {
2499 SerializeNameValueBlock(&builder, push_promise); 2512 SerializeNameValueBlock(&builder, push_promise);
2500 } 2513 }
2501 2514
2502 if (debug_visitor_) { 2515 if (debug_visitor_) {
2503 const size_t payload_len = protocol_version() > SPDY3 ? 2516 const size_t payload_len = protocol_version() > SPDY3 ?
2504 hpack_encoding.size() : 2517 hpack_encoding.size() :
2505 GetSerializedLength(protocol_version(), 2518 GetSerializedLength(protocol_version(),
2506 &(push_promise.name_value_block())); 2519 &(push_promise.name_value_block()));
2507 debug_visitor_->OnSendCompressedFrame(push_promise.stream_id(), 2520 debug_visitor_->OnSendCompressedFrame(push_promise.stream_id(),
(...skipping 14 matching lines...) Expand all
2522 flags |= HEADERS_FLAG_END_HEADERS; 2535 flags |= HEADERS_FLAG_END_HEADERS;
2523 } 2536 }
2524 2537
2525 // The size of this frame, including variable-length name-value block. 2538 // The size of this frame, including variable-length name-value block.
2526 size_t size = GetContinuationMinimumSize(); 2539 size_t size = GetContinuationMinimumSize();
2527 string hpack_encoding; 2540 string hpack_encoding;
2528 hpack_encoder_.EncodeHeaderSet(continuation.name_value_block(), 2541 hpack_encoder_.EncodeHeaderSet(continuation.name_value_block(),
2529 &hpack_encoding); 2542 &hpack_encoding);
2530 size += hpack_encoding.size(); 2543 size += hpack_encoding.size();
2531 2544
2532 SpdyFrameBuilder builder(size); 2545 SpdyFrameBuilder builder(size, protocol_version());
2533 builder.WriteFramePrefix(*this, CONTINUATION, flags, 2546 builder.BeginNewFrame(*this, CONTINUATION, flags,
2534 continuation.stream_id()); 2547 continuation.stream_id());
2535 DCHECK_EQ(GetContinuationMinimumSize(), builder.length()); 2548 DCHECK_EQ(GetContinuationMinimumSize(), builder.length());
2536 2549
2537 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2550 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
2538 2551
2539 if (debug_visitor_) { 2552 if (debug_visitor_) {
2540 const size_t payload_len = hpack_encoding.size(); 2553 const size_t payload_len = hpack_encoding.size();
2541 debug_visitor_->OnSendCompressedFrame(continuation.stream_id(), 2554 debug_visitor_->OnSendCompressedFrame(continuation.stream_id(),
2542 CONTINUATION, payload_len, builder.length()); 2555 CONTINUATION, payload_len, builder.length());
2543 } 2556 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2613 GetSerializedLength(protocol_version(), &headers); 2626 GetSerializedLength(protocol_version(), &headers);
2614 if (!enable_compression_) { 2627 if (!enable_compression_) {
2615 return uncompressed_length; 2628 return uncompressed_length;
2616 } 2629 }
2617 z_stream* compressor = GetHeaderCompressor(); 2630 z_stream* compressor = GetHeaderCompressor();
2618 // Since we'll be performing lots of flushes when compressing the data, 2631 // Since we'll be performing lots of flushes when compressing the data,
2619 // zlib's lower bounds may be insufficient. 2632 // zlib's lower bounds may be insufficient.
2620 return 2 * deflateBound(compressor, uncompressed_length); 2633 return 2 * deflateBound(compressor, uncompressed_length);
2621 } 2634 }
2622 2635
2636 size_t SpdyFramer::GetNumberRequiredContinuationFrames(size_t size) {
2637 const size_t kMaxControlFrameSize = GetControlFrameBufferMaxSize();
2638 DCHECK_GT(protocol_version(), net::SPDY3);
2639 DCHECK_GT(size, kMaxControlFrameSize);
2640 size_t overflow = size - kMaxControlFrameSize;
2641 return overflow / (kMaxControlFrameSize - GetContinuationMinimumSize()) + 1;
2642 }
2643
2644 void SpdyFramer::WritePayloadWithContinuation(SpdyFrameBuilder* builder,
2645 const string& hpack_encoding,
2646 SpdyStreamId stream_id,
2647 SpdyFrameType type) {
2648 const size_t kMaxControlFrameSize = GetControlFrameBufferMaxSize();
2649
2650 // In addition to the prefix, fixed_field_size includes the size of
2651 // any fields that come before the variable-length name/value block.
2652 size_t fixed_field_size = 0;
2653 uint8 end_flag = 0;
2654 uint8 flags = 0;
2655 if (type == HEADERS) {
2656 fixed_field_size = GetHeadersMinimumSize();
2657 end_flag = HEADERS_FLAG_END_HEADERS;
2658 } else if (type == PUSH_PROMISE) {
2659 fixed_field_size = GetPushPromiseMinimumSize();
2660 end_flag = PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2661 } else {
2662 DLOG(FATAL) << "CONTINUATION frames cannot be used with frame type "
2663 << FrameTypeToString(type);
2664 }
2665
2666 // Write as much of the payload as possible into the initial frame.
2667 size_t bytes_remaining = hpack_encoding.size() -
2668 std::min(hpack_encoding.size(),
2669 kMaxControlFrameSize - fixed_field_size);
2670 builder->WriteBytes(&hpack_encoding[0],
2671 hpack_encoding.size() - bytes_remaining);
2672
2673 if (bytes_remaining > 0) {
2674 builder->OverwriteLength(*this,
2675 kMaxControlFrameSize - GetControlFrameHeaderSize());
2676 }
2677
2678 // Tack on CONTINUATION frames for the overflow.
2679 while (bytes_remaining > 0) {
2680 size_t bytes_to_write = std::min(bytes_remaining,
2681 kMaxControlFrameSize -
2682 GetContinuationMinimumSize());
2683 // Write CONTINUATION frame prefix.
2684 if (bytes_remaining == bytes_to_write) {
2685 flags |= end_flag;
2686 }
2687 builder->BeginNewFrame(*this,
2688 CONTINUATION,
2689 flags,
2690 stream_id);
2691 // Write payload fragment.
2692 builder->WriteBytes(&hpack_encoding[hpack_encoding.size() -
2693 bytes_remaining],
2694 bytes_to_write);
2695 bytes_remaining -= bytes_to_write;
2696 }
2697 }
2698
2623 // The following compression setting are based on Brian Olson's analysis. See 2699 // The following compression setting are based on Brian Olson's analysis. See
2624 // https://groups.google.com/group/spdy-dev/browse_thread/thread/dfaf498542fac79 2 2700 // https://groups.google.com/group/spdy-dev/browse_thread/thread/dfaf498542fac79 2
2625 // for more details. 2701 // for more details.
2626 #if defined(USE_SYSTEM_ZLIB) 2702 #if defined(USE_SYSTEM_ZLIB)
2627 // System zlib is not expected to have workaround for http://crbug.com/139744, 2703 // System zlib is not expected to have workaround for http://crbug.com/139744,
2628 // so disable compression in that case. 2704 // so disable compression in that case.
2629 // TODO(phajdan.jr): Remove the special case when it's no longer necessary. 2705 // TODO(phajdan.jr): Remove the special case when it's no longer necessary.
2630 static const int kCompressorLevel = 0; 2706 static const int kCompressorLevel = 0;
2631 #else // !defined(USE_SYSTEM_ZLIB) 2707 #else // !defined(USE_SYSTEM_ZLIB)
2632 static const int kCompressorLevel = 9; 2708 static const int kCompressorLevel = 9;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 const SpdyFrameWithNameValueBlockIR& frame) { 2876 const SpdyFrameWithNameValueBlockIR& frame) {
2801 CHECK_GE(SPDY3, protocol_version()); 2877 CHECK_GE(SPDY3, protocol_version());
2802 if (!enable_compression_) { 2878 if (!enable_compression_) {
2803 return SerializeNameValueBlockWithoutCompression(builder, 2879 return SerializeNameValueBlockWithoutCompression(builder,
2804 frame.name_value_block()); 2880 frame.name_value_block());
2805 } 2881 }
2806 2882
2807 // First build an uncompressed version to be fed into the compressor. 2883 // First build an uncompressed version to be fed into the compressor.
2808 const size_t uncompressed_len = GetSerializedLength( 2884 const size_t uncompressed_len = GetSerializedLength(
2809 protocol_version(), &(frame.name_value_block())); 2885 protocol_version(), &(frame.name_value_block()));
2810 SpdyFrameBuilder uncompressed_builder(uncompressed_len); 2886 SpdyFrameBuilder uncompressed_builder(uncompressed_len, protocol_version());
2811 SerializeNameValueBlockWithoutCompression(&uncompressed_builder, 2887 SerializeNameValueBlockWithoutCompression(&uncompressed_builder,
2812 frame.name_value_block()); 2888 frame.name_value_block());
2813 scoped_ptr<SpdyFrame> uncompressed_payload(uncompressed_builder.take()); 2889 scoped_ptr<SpdyFrame> uncompressed_payload(uncompressed_builder.take());
2814 2890
2815 z_stream* compressor = GetHeaderCompressor(); 2891 z_stream* compressor = GetHeaderCompressor();
2816 if (!compressor) { 2892 if (!compressor) {
2817 LOG(DFATAL) << "Could not obtain compressor."; 2893 LOG(DFATAL) << "Could not obtain compressor.";
2818 return; 2894 return;
2819 } 2895 }
2820 2896
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 builder->Seek(compressed_size); 2935 builder->Seek(compressed_size);
2860 builder->RewriteLength(*this); 2936 builder->RewriteLength(*this);
2861 2937
2862 pre_compress_bytes.Add(uncompressed_len); 2938 pre_compress_bytes.Add(uncompressed_len);
2863 post_compress_bytes.Add(compressed_size); 2939 post_compress_bytes.Add(compressed_size);
2864 2940
2865 compressed_frames.Increment(); 2941 compressed_frames.Increment();
2866 } 2942 }
2867 2943
2868 } // namespace net 2944 } // 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