| OLD | NEW | 
|---|
| 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 <cctype> | 10 #include <cctype> | 
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 146                                                    size_t len) { | 146                                                    size_t len) { | 
| 147   return true; | 147   return true; | 
| 148 } | 148 } | 
| 149 | 149 | 
| 150 bool SpdyFramerVisitorInterface::OnRstStreamFrameData( | 150 bool SpdyFramerVisitorInterface::OnRstStreamFrameData( | 
| 151     const char* rst_stream_data, | 151     const char* rst_stream_data, | 
| 152     size_t len) { | 152     size_t len) { | 
| 153   return true; | 153   return true; | 
| 154 } | 154 } | 
| 155 | 155 | 
| 156 SpdyFramer::SpdyFramer(SpdyFramer::DecoderAdapterFactoryFn adapter_factory) | 156 SpdyFramer::SpdyFramer(SpdyFramer::DecoderAdapterFactoryFn adapter_factory, | 
|  | 157                        CompressionOption option) | 
| 157     : current_frame_buffer_(kControlFrameBufferSize), | 158     : current_frame_buffer_(kControlFrameBufferSize), | 
| 158       expect_continuation_(0), | 159       expect_continuation_(0), | 
| 159       visitor_(NULL), | 160       visitor_(NULL), | 
| 160       debug_visitor_(NULL), | 161       debug_visitor_(NULL), | 
| 161       header_handler_(nullptr), | 162       header_handler_(nullptr), | 
| 162       enable_compression_(true), | 163       compression_option_(option), | 
| 163       probable_http_response_(false), | 164       probable_http_response_(false), | 
| 164       end_stream_when_done_(false) { | 165       end_stream_when_done_(false) { | 
| 165   // TODO(bnc): The way kMaxControlFrameSize is currently interpreted, it | 166   // TODO(bnc): The way kMaxControlFrameSize is currently interpreted, it | 
| 166   // includes the frame header, whereas kSpdyInitialFrameSizeLimit does not. | 167   // includes the frame header, whereas kSpdyInitialFrameSizeLimit does not. | 
| 167   // Therefore this assertion is unnecessarily strict. | 168   // Therefore this assertion is unnecessarily strict. | 
| 168   static_assert(kMaxControlFrameSize <= kSpdyInitialFrameSizeLimit, | 169   static_assert(kMaxControlFrameSize <= kSpdyInitialFrameSizeLimit, | 
| 169                 "Our send limit should be at most our receive limit"); | 170                 "Our send limit should be at most our receive limit"); | 
| 170   Reset(); | 171   Reset(); | 
| 171 | 172 | 
| 172   if (adapter_factory != nullptr) { | 173   if (adapter_factory != nullptr) { | 
| 173     decoder_adapter_ = adapter_factory(this); | 174     decoder_adapter_ = adapter_factory(this); | 
| 174   } | 175   } | 
| 175 } | 176 } | 
| 176 | 177 | 
| 177 SpdyFramer::SpdyFramer() : SpdyFramer(&DecoderAdapterFactory) {} | 178 SpdyFramer::SpdyFramer(CompressionOption option) | 
|  | 179     : SpdyFramer(&DecoderAdapterFactory, option) {} | 
| 178 | 180 | 
| 179 SpdyFramer::~SpdyFramer() { | 181 SpdyFramer::~SpdyFramer() { | 
| 180 } | 182 } | 
| 181 | 183 | 
| 182 void SpdyFramer::Reset() { | 184 void SpdyFramer::Reset() { | 
| 183   if (decoder_adapter_ != nullptr) { | 185   if (decoder_adapter_ != nullptr) { | 
| 184     decoder_adapter_->Reset(); | 186     decoder_adapter_->Reset(); | 
| 185   } | 187   } | 
| 186   state_ = SPDY_READY_FOR_FRAME; | 188   state_ = SPDY_READY_FOR_FRAME; | 
| 187   previous_state_ = SPDY_READY_FOR_FRAME; | 189   previous_state_ = SPDY_READY_FOR_FRAME; | 
| (...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1775 | 1777 | 
| 1776 SpdyFramer::SpdyHeaderFrameIterator::SpdyHeaderFrameIterator( | 1778 SpdyFramer::SpdyHeaderFrameIterator::SpdyHeaderFrameIterator( | 
| 1777     SpdyFramer* framer, | 1779     SpdyFramer* framer, | 
| 1778     std::unique_ptr<SpdyHeadersIR> headers_ir) | 1780     std::unique_ptr<SpdyHeadersIR> headers_ir) | 
| 1779     : headers_ir_(std::move(headers_ir)), | 1781     : headers_ir_(std::move(headers_ir)), | 
| 1780       framer_(framer), | 1782       framer_(framer), | 
| 1781       debug_total_size_(0), | 1783       debug_total_size_(0), | 
| 1782       is_first_frame_(true), | 1784       is_first_frame_(true), | 
| 1783       has_next_frame_(true) { | 1785       has_next_frame_(true) { | 
| 1784   encoder_ = framer_->GetHpackEncoder()->EncodeHeaderSet( | 1786   encoder_ = framer_->GetHpackEncoder()->EncodeHeaderSet( | 
| 1785       headers_ir_->header_block(), framer_->enable_compression_); | 1787       headers_ir_->header_block(), framer_->compression_enabled()); | 
| 1786 } | 1788 } | 
| 1787 | 1789 | 
| 1788 SpdyFramer::SpdyHeaderFrameIterator::~SpdyHeaderFrameIterator() {} | 1790 SpdyFramer::SpdyHeaderFrameIterator::~SpdyHeaderFrameIterator() {} | 
| 1789 | 1791 | 
| 1790 SpdySerializedFrame SpdyFramer::SpdyHeaderFrameIterator::NextFrame() { | 1792 SpdySerializedFrame SpdyFramer::SpdyHeaderFrameIterator::NextFrame() { | 
| 1791   if (!has_next_frame_) { | 1793   if (!has_next_frame_) { | 
| 1792     SPDY_BUG << "SpdyFramer::SpdyHeaderFrameIterator::NextFrame called without " | 1794     SPDY_BUG << "SpdyFramer::SpdyHeaderFrameIterator::NextFrame called without " | 
| 1793              << "a next frame."; | 1795              << "a next frame."; | 
| 1794     return SpdySerializedFrame(); | 1796     return SpdySerializedFrame(); | 
| 1795   } | 1797   } | 
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1997     size += headers.padding_payload_len(); | 1999     size += headers.padding_payload_len(); | 
| 1998   } | 2000   } | 
| 1999 | 2001 | 
| 2000   int weight = 0; | 2002   int weight = 0; | 
| 2001   if (headers.has_priority()) { | 2003   if (headers.has_priority()) { | 
| 2002     weight = ClampHttp2Weight(headers.weight()); | 2004     weight = ClampHttp2Weight(headers.weight()); | 
| 2003     size += 5; | 2005     size += 5; | 
| 2004   } | 2006   } | 
| 2005 | 2007 | 
| 2006   string hpack_encoding; | 2008   string hpack_encoding; | 
| 2007   if (enable_compression_) { | 2009   if (compression_enabled()) { | 
| 2008     GetHpackEncoder()->EncodeHeaderSet(headers.header_block(), &hpack_encoding); | 2010     GetHpackEncoder()->EncodeHeaderSet(headers.header_block(), &hpack_encoding); | 
| 2009   } else { | 2011   } else { | 
| 2010     GetHpackEncoder()->EncodeHeaderSetWithoutCompression(headers.header_block(), | 2012     GetHpackEncoder()->EncodeHeaderSetWithoutCompression(headers.header_block(), | 
| 2011                                                          &hpack_encoding); | 2013                                                          &hpack_encoding); | 
| 2012   } | 2014   } | 
| 2013   size += hpack_encoding.size(); | 2015   size += hpack_encoding.size(); | 
| 2014   if (size > kMaxControlFrameSize) { | 2016   if (size > kMaxControlFrameSize) { | 
| 2015     size += GetNumberRequiredContinuationFrames(size) * | 2017     size += GetNumberRequiredContinuationFrames(size) * | 
| 2016             GetContinuationMinimumSize(); | 2018             GetContinuationMinimumSize(); | 
| 2017     flags &= ~HEADERS_FLAG_END_HEADERS; | 2019     flags &= ~HEADERS_FLAG_END_HEADERS; | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2074   // The size of this frame, including variable-length name-value block. | 2076   // The size of this frame, including variable-length name-value block. | 
| 2075   size_t size = GetPushPromiseMinimumSize(); | 2077   size_t size = GetPushPromiseMinimumSize(); | 
| 2076 | 2078 | 
| 2077   if (push_promise.padded()) { | 2079   if (push_promise.padded()) { | 
| 2078     flags |= PUSH_PROMISE_FLAG_PADDED; | 2080     flags |= PUSH_PROMISE_FLAG_PADDED; | 
| 2079     size += kPadLengthFieldSize; | 2081     size += kPadLengthFieldSize; | 
| 2080     size += push_promise.padding_payload_len(); | 2082     size += push_promise.padding_payload_len(); | 
| 2081   } | 2083   } | 
| 2082 | 2084 | 
| 2083   string hpack_encoding; | 2085   string hpack_encoding; | 
| 2084   if (enable_compression_) { | 2086   if (compression_enabled()) { | 
| 2085     GetHpackEncoder()->EncodeHeaderSet(push_promise.header_block(), | 2087     GetHpackEncoder()->EncodeHeaderSet(push_promise.header_block(), | 
| 2086                                        &hpack_encoding); | 2088                                        &hpack_encoding); | 
| 2087   } else { | 2089   } else { | 
| 2088     GetHpackEncoder()->EncodeHeaderSetWithoutCompression( | 2090     GetHpackEncoder()->EncodeHeaderSetWithoutCompression( | 
| 2089         push_promise.header_block(), &hpack_encoding); | 2091         push_promise.header_block(), &hpack_encoding); | 
| 2090   } | 2092   } | 
| 2091   size += hpack_encoding.size(); | 2093   size += hpack_encoding.size(); | 
| 2092   if (size > kMaxControlFrameSize) { | 2094   if (size > kMaxControlFrameSize) { | 
| 2093     size += GetNumberRequiredContinuationFrames(size) * | 2095     size += GetNumberRequiredContinuationFrames(size) * | 
| 2094             GetContinuationMinimumSize(); | 2096             GetContinuationMinimumSize(); | 
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2438   builder->WriteUInt32(header_block.size()); | 2440   builder->WriteUInt32(header_block.size()); | 
| 2439 | 2441 | 
| 2440   // Serialize each header. | 2442   // Serialize each header. | 
| 2441   for (const auto& header : header_block) { | 2443   for (const auto& header : header_block) { | 
| 2442     builder->WriteStringPiece32(base::ToLowerASCII(header.first)); | 2444     builder->WriteStringPiece32(base::ToLowerASCII(header.first)); | 
| 2443     builder->WriteStringPiece32(header.second); | 2445     builder->WriteStringPiece32(header.second); | 
| 2444   } | 2446   } | 
| 2445 } | 2447 } | 
| 2446 | 2448 | 
| 2447 }  // namespace net | 2449 }  // namespace net | 
| OLD | NEW | 
|---|