| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/http2_frame_decoder_adapter.h" | 5 #include "net/spdy/http2_frame_decoder_adapter.h" |
| 6 | 6 |
| 7 // Logging policy: If an error in the input is detected, VLOG(n) is used so that | 7 // Logging policy: If an error in the input is detected, VLOG(n) is used so that |
| 8 // the option exists to debug the situation. Otherwise, this code mostly uses | 8 // the option exists to debug the situation. Otherwise, this code mostly uses |
| 9 // DVLOG so that the logging does not slow down production code when things are | 9 // DVLOG so that the logging does not slow down production code when things are |
| 10 // working OK. | 10 // working OK. |
| 11 | 11 |
| 12 #include <stddef.h> | 12 #include <stddef.h> |
| 13 | 13 |
| 14 #include <cstdint> | 14 #include <cstdint> |
| 15 #include <cstring> | 15 #include <cstring> |
| 16 #include <string> | |
| 17 #include <utility> | 16 #include <utility> |
| 18 | 17 |
| 19 #include "base/logging.h" | 18 #include "base/logging.h" |
| 20 #include "base/optional.h" | 19 #include "base/optional.h" |
| 21 #include "base/sys_byteorder.h" | 20 #include "base/sys_byteorder.h" |
| 22 #include "net/http2/decoder/decode_buffer.h" | 21 #include "net/http2/decoder/decode_buffer.h" |
| 23 #include "net/http2/decoder/decode_status.h" | 22 #include "net/http2/decoder/decode_status.h" |
| 24 #include "net/http2/decoder/http2_frame_decoder.h" | 23 #include "net/http2/decoder/http2_frame_decoder.h" |
| 25 #include "net/http2/decoder/http2_frame_decoder_listener.h" | 24 #include "net/http2/decoder/http2_frame_decoder_listener.h" |
| 26 #include "net/http2/http2_constants.h" | 25 #include "net/http2/http2_constants.h" |
| 27 #include "net/http2/http2_structures.h" | 26 #include "net/http2/http2_structures.h" |
| 28 #include "net/spdy/hpack/hpack_decoder_interface.h" | 27 #include "net/spdy/hpack/hpack_decoder_interface.h" |
| 29 #include "net/spdy/hpack/hpack_header_table.h" | 28 #include "net/spdy/hpack/hpack_header_table.h" |
| 30 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" | 29 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" |
| 30 #include "net/spdy/platform/api/spdy_string.h" |
| 31 #include "net/spdy/spdy_alt_svc_wire_format.h" | 31 #include "net/spdy/spdy_alt_svc_wire_format.h" |
| 32 #include "net/spdy/spdy_bug_tracker.h" | 32 #include "net/spdy/spdy_bug_tracker.h" |
| 33 #include "net/spdy/spdy_frame_builder.h" | 33 #include "net/spdy/spdy_frame_builder.h" |
| 34 #include "net/spdy/spdy_header_block.h" | 34 #include "net/spdy/spdy_header_block.h" |
| 35 #include "net/spdy/spdy_headers_handler_interface.h" | 35 #include "net/spdy/spdy_headers_handler_interface.h" |
| 36 #include "net/spdy/spdy_protocol.h" | 36 #include "net/spdy/spdy_protocol.h" |
| 37 | 37 |
| 38 using std::string; | |
| 39 | |
| 40 namespace net { | 38 namespace net { |
| 41 | 39 |
| 42 namespace { | 40 namespace { |
| 43 | 41 |
| 44 const bool kHasPriorityFields = true; | 42 const bool kHasPriorityFields = true; |
| 45 const bool kNotHasPriorityFields = false; | 43 const bool kNotHasPriorityFields = false; |
| 46 | 44 |
| 47 bool IsPaddable(Http2FrameType type) { | 45 bool IsPaddable(Http2FrameType type) { |
| 48 return type == Http2FrameType::DATA || type == Http2FrameType::HEADERS || | 46 return type == Http2FrameType::DATA || type == Http2FrameType::HEADERS || |
| 49 type == Http2FrameType::PUSH_PROMISE; | 47 type == Http2FrameType::PUSH_PROMISE; |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 | 931 |
| 934 // If decoding an HPACK block that is split across multiple frames, this holds | 932 // If decoding an HPACK block that is split across multiple frames, this holds |
| 935 // the frame header of the HEADERS or PUSH_PROMISE that started the block. | 933 // the frame header of the HEADERS or PUSH_PROMISE that started the block. |
| 936 Http2FrameHeader hpack_first_frame_header_; | 934 Http2FrameHeader hpack_first_frame_header_; |
| 937 | 935 |
| 938 // Amount of trailing padding. Currently used just as an indicator of whether | 936 // Amount of trailing padding. Currently used just as an indicator of whether |
| 939 // OnPadLength has been called. | 937 // OnPadLength has been called. |
| 940 base::Optional<size_t> opt_pad_length_; | 938 base::Optional<size_t> opt_pad_length_; |
| 941 | 939 |
| 942 // Temporary buffers for the AltSvc fields. | 940 // Temporary buffers for the AltSvc fields. |
| 943 string alt_svc_origin_; | 941 SpdyString alt_svc_origin_; |
| 944 string alt_svc_value_; | 942 SpdyString alt_svc_value_; |
| 945 | 943 |
| 946 // Listener used if we transition to an error state; the listener ignores all | 944 // Listener used if we transition to an error state; the listener ignores all |
| 947 // the callbacks. | 945 // the callbacks. |
| 948 Http2FrameDecoderNoOpListener no_op_listener_; | 946 Http2FrameDecoderNoOpListener no_op_listener_; |
| 949 | 947 |
| 950 // Next frame type expected. Currently only used for CONTINUATION frames, | 948 // Next frame type expected. Currently only used for CONTINUATION frames, |
| 951 // but could be used for detecting whether the first frame is a SETTINGS | 949 // but could be used for detecting whether the first frame is a SETTINGS |
| 952 // frame. | 950 // frame. |
| 953 // TODO(jamessyng): Provide means to indicate that decoder should require | 951 // TODO(jamessyng): Provide means to indicate that decoder should require |
| 954 // SETTINGS frame as the first frame. | 952 // SETTINGS frame as the first frame. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 993 |
| 996 } // namespace | 994 } // namespace |
| 997 | 995 |
| 998 std::unique_ptr<SpdyFramerDecoderAdapter> CreateHttp2FrameDecoderAdapter( | 996 std::unique_ptr<SpdyFramerDecoderAdapter> CreateHttp2FrameDecoderAdapter( |
| 999 SpdyFramer* outer_framer) { | 997 SpdyFramer* outer_framer) { |
| 1000 return std::unique_ptr<SpdyFramerDecoderAdapter>( | 998 return std::unique_ptr<SpdyFramerDecoderAdapter>( |
| 1001 new Http2DecoderAdapter(outer_framer)); | 999 new Http2DecoderAdapter(outer_framer)); |
| 1002 } | 1000 } |
| 1003 | 1001 |
| 1004 } // namespace net | 1002 } // namespace net |
| OLD | NEW |