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

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

Issue 247283003: HPACK: Implement delta encoding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/hpack_round_trip_test.cc ('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 "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/stats_counters.h" 9 #include "base/metrics/stats_counters.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 bool SpdyFramerVisitorInterface::OnRstStreamFrameData( 118 bool SpdyFramerVisitorInterface::OnRstStreamFrameData(
119 const char* rst_stream_data, 119 const char* rst_stream_data,
120 size_t len) { 120 size_t len) {
121 return true; 121 return true;
122 } 122 }
123 123
124 SpdyFramer::SpdyFramer(SpdyMajorVersion version) 124 SpdyFramer::SpdyFramer(SpdyMajorVersion version)
125 : current_frame_buffer_(new char[kControlFrameBufferSize]), 125 : current_frame_buffer_(new char[kControlFrameBufferSize]),
126 enable_compression_(true), 126 enable_compression_(true),
127 hpack_encoder_(ObtainHpackHuffmanTable()),
127 hpack_decoder_(ObtainHpackHuffmanTable()), 128 hpack_decoder_(ObtainHpackHuffmanTable()),
128 visitor_(NULL), 129 visitor_(NULL),
129 debug_visitor_(NULL), 130 debug_visitor_(NULL),
130 display_protocol_("SPDY"), 131 display_protocol_("SPDY"),
131 spdy_version_(version), 132 spdy_version_(version),
132 syn_frame_processed_(false), 133 syn_frame_processed_(false),
133 probable_http_response_(false), 134 probable_http_response_(false),
134 expect_continuation_(0), 135 expect_continuation_(0),
135 end_stream_when_done_(false) { 136 end_stream_when_done_(false) {
136 DCHECK_GE(spdy_version_, SPDY_MIN_VERSION); 137 DCHECK_GE(spdy_version_, SPDY_MIN_VERSION);
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 if (priority > GetLowestPriority()) { 2157 if (priority > GetLowestPriority()) {
2157 DLOG(DFATAL) << "Priority out-of-bounds."; 2158 DLOG(DFATAL) << "Priority out-of-bounds.";
2158 priority = GetLowestPriority(); 2159 priority = GetLowestPriority();
2159 } 2160 }
2160 2161
2161 // The size of this frame, including variable-length name-value block. 2162 // The size of this frame, including variable-length name-value block.
2162 size_t size = GetSynStreamMinimumSize(); 2163 size_t size = GetSynStreamMinimumSize();
2163 2164
2164 string hpack_encoding; 2165 string hpack_encoding;
2165 if (protocol_version() > SPDY3) { 2166 if (protocol_version() > SPDY3) {
2166 hpack_encoder_.EncodeHeaderSet(syn_stream.name_value_block(), 2167 if (enable_compression_) {
2167 &hpack_encoding); 2168 hpack_encoder_.EncodeHeaderSet(
2169 syn_stream.name_value_block(), &hpack_encoding);
2170 } else {
2171 hpack_encoder_.EncodeHeaderSetWithoutCompression(
2172 syn_stream.name_value_block(), &hpack_encoding);
2173 }
2168 size += hpack_encoding.size(); 2174 size += hpack_encoding.size();
2169 } else { 2175 } else {
2170 size += GetSerializedLength(syn_stream.name_value_block()); 2176 size += GetSerializedLength(syn_stream.name_value_block());
2171 } 2177 }
2172 2178
2173 SpdyFrameBuilder builder(size, protocol_version()); 2179 SpdyFrameBuilder builder(size, protocol_version());
2174 if (protocol_version() <= SPDY3) { 2180 if (protocol_version() <= SPDY3) {
2175 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags); 2181 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags);
2176 builder.WriteUInt32(syn_stream.stream_id()); 2182 builder.WriteUInt32(syn_stream.stream_id());
2177 builder.WriteUInt32(syn_stream.associated_to_stream_id()); 2183 builder.WriteUInt32(syn_stream.associated_to_stream_id());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 // we never expect to have to overflow into a CONTINUATION frame. 2222 // we never expect to have to overflow into a CONTINUATION frame.
2217 if (protocol_version() > SPDY3) { 2223 if (protocol_version() > SPDY3) {
2218 flags |= HEADERS_FLAG_END_HEADERS; 2224 flags |= HEADERS_FLAG_END_HEADERS;
2219 } 2225 }
2220 2226
2221 // The size of this frame, including variable-length name-value block. 2227 // The size of this frame, including variable-length name-value block.
2222 size_t size = GetSynReplyMinimumSize(); 2228 size_t size = GetSynReplyMinimumSize();
2223 2229
2224 string hpack_encoding; 2230 string hpack_encoding;
2225 if (protocol_version() > SPDY3) { 2231 if (protocol_version() > SPDY3) {
2226 hpack_encoder_.EncodeHeaderSet(syn_reply.name_value_block(), 2232 if (enable_compression_) {
2227 &hpack_encoding); 2233 hpack_encoder_.EncodeHeaderSet(
2234 syn_reply.name_value_block(), &hpack_encoding);
2235 } else {
2236 hpack_encoder_.EncodeHeaderSetWithoutCompression(
2237 syn_reply.name_value_block(), &hpack_encoding);
2238 }
2228 size += hpack_encoding.size(); 2239 size += hpack_encoding.size();
2229 } else { 2240 } else {
2230 size += GetSerializedLength(syn_reply.name_value_block()); 2241 size += GetSerializedLength(syn_reply.name_value_block());
2231 } 2242 }
2232 2243
2233 SpdyFrameBuilder builder(size, protocol_version()); 2244 SpdyFrameBuilder builder(size, protocol_version());
2234 if (protocol_version() <= SPDY3) { 2245 if (protocol_version() <= SPDY3) {
2235 builder.WriteControlFrameHeader(*this, SYN_REPLY, flags); 2246 builder.WriteControlFrameHeader(*this, SYN_REPLY, flags);
2236 builder.WriteUInt32(syn_reply.stream_id()); 2247 builder.WriteUInt32(syn_reply.stream_id());
2237 } else { 2248 } else {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
2435 if (headers.has_priority()) { 2446 if (headers.has_priority()) {
2436 if (priority > GetLowestPriority()) { 2447 if (priority > GetLowestPriority()) {
2437 DLOG(DFATAL) << "Priority out-of-bounds."; 2448 DLOG(DFATAL) << "Priority out-of-bounds.";
2438 priority = GetLowestPriority(); 2449 priority = GetLowestPriority();
2439 } 2450 }
2440 size += 4; 2451 size += 4;
2441 } 2452 }
2442 2453
2443 string hpack_encoding; 2454 string hpack_encoding;
2444 if (protocol_version() > SPDY3) { 2455 if (protocol_version() > SPDY3) {
2445 hpack_encoder_.EncodeHeaderSet(headers.name_value_block(), &hpack_encoding); 2456 if (enable_compression_) {
2457 hpack_encoder_.EncodeHeaderSet(
2458 headers.name_value_block(), &hpack_encoding);
2459 } else {
2460 hpack_encoder_.EncodeHeaderSetWithoutCompression(
2461 headers.name_value_block(), &hpack_encoding);
2462 }
2446 size += hpack_encoding.size(); 2463 size += hpack_encoding.size();
2447 if (size > GetControlFrameBufferMaxSize()) { 2464 if (size > GetControlFrameBufferMaxSize()) {
2448 size += GetNumberRequiredContinuationFrames(size) * 2465 size += GetNumberRequiredContinuationFrames(size) *
2449 GetContinuationMinimumSize(); 2466 GetContinuationMinimumSize();
2450 flags &= ~HEADERS_FLAG_END_HEADERS; 2467 flags &= ~HEADERS_FLAG_END_HEADERS;
2451 } 2468 }
2452 } else { 2469 } else {
2453 size += GetSerializedLength(headers.name_value_block()); 2470 size += GetSerializedLength(headers.name_value_block());
2454 } 2471 }
2455 2472
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 // get overwritten below, so we should probably just get rid of the 2543 // get overwritten below, so we should probably just get rid of the
2527 // end_push_promise field. 2544 // end_push_promise field.
2528 if (push_promise.end_push_promise()) { 2545 if (push_promise.end_push_promise()) {
2529 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE; 2546 flags |= PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2530 } 2547 }
2531 // The size of this frame, including variable-length name-value block. 2548 // The size of this frame, including variable-length name-value block.
2532 size_t size = GetPushPromiseMinimumSize(); 2549 size_t size = GetPushPromiseMinimumSize();
2533 2550
2534 string hpack_encoding; 2551 string hpack_encoding;
2535 if (protocol_version() > SPDY3) { 2552 if (protocol_version() > SPDY3) {
2536 hpack_encoder_.EncodeHeaderSet(push_promise.name_value_block(), 2553 if (enable_compression_) {
2537 &hpack_encoding); 2554 hpack_encoder_.EncodeHeaderSet(
2555 push_promise.name_value_block(), &hpack_encoding);
2556 } else {
2557 hpack_encoder_.EncodeHeaderSetWithoutCompression(
2558 push_promise.name_value_block(), &hpack_encoding);
2559 }
2538 size += hpack_encoding.size(); 2560 size += hpack_encoding.size();
2539 if (size > GetControlFrameBufferMaxSize()) { 2561 if (size > GetControlFrameBufferMaxSize()) {
2540 size += GetNumberRequiredContinuationFrames(size) * 2562 size += GetNumberRequiredContinuationFrames(size) *
2541 GetContinuationMinimumSize(); 2563 GetContinuationMinimumSize();
2542 flags &= ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE; 2564 flags &= ~PUSH_PROMISE_FLAG_END_PUSH_PROMISE;
2543 } 2565 }
2544 } else { 2566 } else {
2545 size += GetSerializedLength(push_promise.name_value_block()); 2567 size += GetSerializedLength(push_promise.name_value_block());
2546 } 2568 }
2547 2569
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2581 const SpdyContinuationIR& continuation) { 2603 const SpdyContinuationIR& continuation) {
2582 CHECK_LT(SPDY3, protocol_version()); 2604 CHECK_LT(SPDY3, protocol_version());
2583 uint8 flags = 0; 2605 uint8 flags = 0;
2584 if (continuation.end_headers()) { 2606 if (continuation.end_headers()) {
2585 flags |= HEADERS_FLAG_END_HEADERS; 2607 flags |= HEADERS_FLAG_END_HEADERS;
2586 } 2608 }
2587 2609
2588 // The size of this frame, including variable-length name-value block. 2610 // The size of this frame, including variable-length name-value block.
2589 size_t size = GetContinuationMinimumSize(); 2611 size_t size = GetContinuationMinimumSize();
2590 string hpack_encoding; 2612 string hpack_encoding;
2591 hpack_encoder_.EncodeHeaderSet(continuation.name_value_block(), 2613 if (enable_compression_) {
2592 &hpack_encoding); 2614 hpack_encoder_.EncodeHeaderSet(
2615 continuation.name_value_block(), &hpack_encoding);
2616 } else {
2617 hpack_encoder_.EncodeHeaderSetWithoutCompression(
2618 continuation.name_value_block(), &hpack_encoding);
2619 }
2593 size += hpack_encoding.size(); 2620 size += hpack_encoding.size();
2594 2621
2595 SpdyFrameBuilder builder(size, protocol_version()); 2622 SpdyFrameBuilder builder(size, protocol_version());
2596 builder.BeginNewFrame(*this, CONTINUATION, flags, 2623 builder.BeginNewFrame(*this, CONTINUATION, flags,
2597 continuation.stream_id()); 2624 continuation.stream_id());
2598 DCHECK_EQ(GetContinuationMinimumSize(), builder.length()); 2625 DCHECK_EQ(GetContinuationMinimumSize(), builder.length());
2599 2626
2600 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size()); 2627 builder.WriteBytes(&hpack_encoding[0], hpack_encoding.size());
2601 2628
2602 if (debug_visitor_) { 2629 if (debug_visitor_) {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2988 builder->Seek(compressed_size); 3015 builder->Seek(compressed_size);
2989 builder->RewriteLength(*this); 3016 builder->RewriteLength(*this);
2990 3017
2991 pre_compress_bytes.Add(uncompressed_len); 3018 pre_compress_bytes.Add(uncompressed_len);
2992 post_compress_bytes.Add(compressed_size); 3019 post_compress_bytes.Add(compressed_size);
2993 3020
2994 compressed_frames.Increment(); 3021 compressed_frames.Increment();
2995 } 3022 }
2996 3023
2997 } // namespace net 3024 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack_round_trip_test.cc ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698