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

Side by Side Diff: net/spdy/hpack/hpack_decoder.h

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 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
« no previous file with comments | « net/spdy/hpack/hpack_constants.cc ('k') | net/spdy/hpack/hpack_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_SPDY_HPACK_HPACK_DECODER_H_
6 #define NET_SPDY_HPACK_HPACK_DECODER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <memory>
13 #include <vector>
14
15 #include "base/macros.h"
16 #include "net/base/net_export.h"
17 #include "net/spdy/hpack/hpack_decoder_interface.h"
18 #include "net/spdy/hpack/hpack_header_table.h"
19 #include "net/spdy/hpack/hpack_input_stream.h"
20 #include "net/spdy/platform/api/spdy_string.h"
21 #include "net/spdy/platform/api/spdy_string_piece.h"
22 #include "net/spdy/spdy_headers_handler_interface.h"
23 #include "net/spdy/spdy_protocol.h"
24
25 // An HpackDecoder decodes header sets as outlined in
26 // http://tools.ietf.org/html/rfc7541.
27
28 namespace net {
29
30 namespace test {
31 class HpackDecoderPeer;
32 } // namespace test
33
34 class NET_EXPORT_PRIVATE HpackDecoder : public HpackDecoderInterface {
35 public:
36 friend class test::HpackDecoderPeer;
37
38 HpackDecoder();
39 ~HpackDecoder() override;
40
41 // Called upon sending a SETTINGS_HEADER_TABLE_SIZE value.
42 void ApplyHeaderTableSizeSetting(size_t size_setting) override;
43
44 // If a SpdyHeadersHandlerInterface is provided, HpackDecoder will emit
45 // headers to it rather than accumulating them in a SpdyHeaderBlock.
46 void HandleControlFrameHeadersStart(
47 SpdyHeadersHandlerInterface* handler) override;
48
49 // Called as headers data arrives. Returns false if an error occurred.
50 // TODO(jgraettinger): A future version of this method will incrementally
51 // parse and deliver headers via SpdyHeadersHandlerInterface. For now,
52 // header data is buffered until HandleControlFrameHeadersComplete().
53 bool HandleControlFrameHeadersData(const char* headers_data,
54 size_t headers_data_length) override;
55
56 // Called after a headers block has been completely delivered via
57 // HandleControlFrameHeadersData(). Returns false if an error
58 // occurred. |compressed_len| if non-null will be set to the size
59 // of the encoded buffered block that was accumulated in
60 // HandleControlFrameHeadersData(), to support subsequent
61 // calculation of compression percentage. Clears |handler_|.
62 // TODO(jgraettinger): A
63 // future version of this method will simply deliver the Cookie
64 // header (which has been incrementally reconstructed) and notify
65 // the visitor that the block is finished.
66 bool HandleControlFrameHeadersComplete(size_t* compressed_len) override;
67
68 // Accessor for the most recently decoded headers block. Valid until the next
69 // call to HandleControlFrameHeadersData().
70 // TODO(birenroy): Remove this method when all users of HpackDecoder specify
71 // a SpdyHeadersHandlerInterface.
72 const SpdyHeaderBlock& decoded_block() const override;
73
74 void SetHeaderTableDebugVisitor(
75 std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor)
76 override;
77
78 void set_max_decode_buffer_size_bytes(
79 size_t max_decode_buffer_size_bytes) override;
80
81 size_t EstimateMemoryUsage() const override;
82
83 private:
84 // Adds the header representation to |decoded_block_|, applying the
85 // following rules:
86 // - Multiple values of the Cookie header are joined, delmited by '; '.
87 // This reconstruction is required to properly handle Cookie crumbling
88 // (as per section 8.1.2.5 in RFC 7540).
89 // - Multiple values of other headers are joined and delimited by '\0'.
90 // Note that this may be too accomodating, as the sender's HTTP2 layer
91 // should have already joined and delimited these values.
92 //
93 // Returns false if a pseudo-header field follows a regular header one, which
94 // MUST be treated as malformed, as per sections 8.1.2.3. of the HTTP2
95 // specification (RFC 7540).
96 //
97 bool HandleHeaderRepresentation(SpdyStringPiece name, SpdyStringPiece value);
98
99 // Handlers for decoding HPACK opcodes and header representations
100 // (or parts thereof). These methods return true on success and
101 // false on error.
102 bool DecodeNextOpcodeWrapper(HpackInputStream* input_stream);
103 bool DecodeNextOpcode(HpackInputStream* input_stream);
104 bool DecodeNextHeaderTableSizeUpdate(HpackInputStream* input_stream);
105 bool DecodeNextIndexedHeader(HpackInputStream* input_stream);
106 bool DecodeNextLiteralHeader(HpackInputStream* input_stream,
107 bool should_index);
108 bool DecodeNextName(HpackInputStream* input_stream,
109 SpdyStringPiece* next_name);
110 bool DecodeNextStringLiteral(HpackInputStream* input_stream,
111 bool is_header_key, // As distinct from a value.
112 SpdyStringPiece* output);
113
114 HpackHeaderTable header_table_;
115
116 // TODO(jgraettinger): Buffer for headers data, and storage for the last-
117 // processed headers block. Both will be removed with the switch to
118 // SpdyHeadersHandlerInterface.
119 SpdyString headers_block_buffer_;
120 SpdyHeaderBlock decoded_block_;
121
122 // Scratch space for storing decoded literals.
123 SpdyString key_buffer_, value_buffer_;
124
125 // If non-NULL, handles decoded headers.
126 SpdyHeadersHandlerInterface* handler_;
127 size_t total_header_bytes_;
128
129 // How much encoded data this decoder is willing to buffer.
130 size_t max_decode_buffer_size_bytes_ = 32 * 1024; // 32 KB
131
132 // Total bytes have been removed from headers_block_buffer_.
133 // Its value is updated during incremental decoding.
134 uint32_t total_parsed_bytes_;
135
136 // Flag to keep track of having seen the header block start.
137 bool header_block_started_;
138
139 // Number of dynamic table size updates seen at the start; a max of two
140 // are permitted.
141 uint8_t size_updates_seen_;
142
143 // Are dynamic table size updates allowed at this point in decoding? True
144 // at the start, but not once we've seen a header entry.
145 bool size_updates_allowed_;
146
147 // Saved value of --chromium_http2_flag_add_hpack_incremental_decode.
148 bool incremental_decode_;
149
150 DISALLOW_COPY_AND_ASSIGN(HpackDecoder);
151 };
152
153 } // namespace net
154
155 #endif // NET_SPDY_HPACK_HPACK_DECODER_H_
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_constants.cc ('k') | net/spdy/hpack/hpack_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698