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

Side by Side Diff: net/http2/hpack/decoder/hpack_decoder_state.h

Issue 2619043003: Add HpackDecoderState and HpackDecoderListener. (Closed)
Patch Set: Rebase. Created 3 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // HpackDecoderState maintains the HPACK decompressor state; i.e. updates the
6 // HPACK dynamic table according to RFC 7541 as the entries in an HPACK block
7 // are decoded, and reads from the static and dynamic tables in order to build
8 // complete header entries. Calls an HpackDecoderListener with the completely
9 // decoded headers (i.e. after resolving table indices into names or values),
10 // thus translating the decoded HPACK entries into HTTP/2 headers.
11
12 #ifndef NET_HTTP2_HPACK_DECODER_HPACK_DECODER_STATE_H_
13 #define NET_HTTP2_HPACK_DECODER_HPACK_DECODER_STATE_H_
14
15 #include <stddef.h>
16 #include <stdint.h>
17
18 #include "base/macros.h"
19 #include "base/strings/string_piece.h"
20 #include "net/base/net_export.h"
21 #include "net/http2/hpack/decoder/hpack_decoder_listener.h"
22 #include "net/http2/hpack/decoder/hpack_decoder_string_buffer.h"
23 #include "net/http2/hpack/decoder/hpack_decoder_tables.h"
24 #include "net/http2/hpack/decoder/hpack_whole_entry_listener.h"
25 #include "net/http2/hpack/http2_hpack_constants.h"
26
27 namespace net {
28 namespace test {
29 class HpackDecoderStatePeer;
30 } // namespace test
31
32 class NET_EXPORT HpackDecoderState : public HpackWholeEntryListener {
33 public:
34 explicit HpackDecoderState(HpackDecoderListener* listener);
35 ~HpackDecoderState() override;
36
37 // Set the listener to be notified when a whole entry has been decoded,
38 // including resolving name or name and value references.
39 // The listener may be changed at any time.
40 void set_listener(HpackDecoderListener* listener);
41 HpackDecoderListener* listener() const { return listener_; }
42
43 // ApplyHeaderTableSizeSetting notifies this object that this endpoint has
44 // received a SETTINGS ACK frame acknowledging an earlier SETTINGS frame from
45 // this endpoint specifying a new value for SETTINGS_HEADER_TABLE_SIZE (the
46 // maximum size of the dynamic table that this endpoint will use to decode
47 // HPACK blocks).
48 // Because a SETTINGS frame can contain SETTINGS_HEADER_TABLE_SIZE values,
49 // the caller must keep track of those multiple changes, and make
50 // corresponding calls to this method. In particular, a call must be made
51 // with the lowest value acknowledged by the peer, and a call must be made
52 // with the final value acknowledged, in that order; additional calls may
53 // be made if additional values were sent. These calls must be made between
54 // decoding the SETTINGS ACK, and before the next HPACK block is decoded.
55 void ApplyHeaderTableSizeSetting(uint32_t max_header_table_size);
56
57 // OnHeaderBlockStart notifies this object that we're starting to decode the
58 // HPACK payload of a HEADERS or PUSH_PROMISE frame.
59 void OnHeaderBlockStart();
60
61 // Implement the HpackWholeEntryListener methods, each of which notifies this
62 // object when an entire entry has been decoded.
63 void OnIndexedHeader(size_t index) override;
64 void OnNameIndexAndLiteralValue(
65 HpackEntryType entry_type,
66 size_t name_index,
67 HpackDecoderStringBuffer* value_buffer) override;
68 void OnLiteralNameAndValue(HpackEntryType entry_type,
69 HpackDecoderStringBuffer* name_buffer,
70 HpackDecoderStringBuffer* value_buffer) override;
71 void OnDynamicTableSizeUpdate(size_t size) override;
72 void OnHpackDecodeError(base::StringPiece error_message) override;
73
74 // OnHeaderBlockEnd notifies this object that an entire HPACK block has been
75 // decoded, which might have extended into CONTINUATION blocks.
76 void OnHeaderBlockEnd();
77
78 // Was an error detected? After an error has been detected and reported,
79 // no further callbacks will be made to the listener.
80 bool error_detected() const { return error_detected_; }
81
82 const HpackDecoderTables& decoder_tables_for_test() const {
83 return decoder_tables_;
84 }
85
86 private:
87 friend class test::HpackDecoderStatePeer;
88
89 // Reports an error to the listener IF this is the first error detected.
90 void ReportError(base::StringPiece error_message);
91
92 // The static and dynamic HPACK tables.
93 HpackDecoderTables decoder_tables_;
94
95 // The listener to be notified of headers, the start and end of header
96 // lists, and of errors.
97 HpackDecoderListener* listener_;
98
99 // The most recent HEADER_TABLE_SIZE setting acknowledged by the peer.
100 uint32_t final_header_table_size_;
101
102 // The lowest HEADER_TABLE_SIZE setting acknowledged by the peer; valid until
103 // the next HPACK block is decoded.
104 // TODO(jamessynge): Test raising the HEADER_TABLE_SIZE.
105 uint32_t lowest_header_table_size_;
106
107 // Must the next (first) HPACK entry be a dynamic table size update?
108 bool require_dynamic_table_size_update_;
109
110 // May the next (first or second) HPACK entry be a dynamic table size update?
111 bool allow_dynamic_table_size_update_;
112
113 // Have we already seen a dynamic table size update in this HPACK block?
114 bool saw_dynamic_table_size_update_;
115
116 // Has an error already been detected and reported to the listener?
117 bool error_detected_;
118
119 DISALLOW_COPY_AND_ASSIGN(HpackDecoderState);
120 };
121
122 } // namespace net
123
124 #endif // NET_HTTP2_HPACK_DECODER_HPACK_DECODER_STATE_H_
OLDNEW
« no previous file with comments | « net/http2/hpack/decoder/hpack_decoder_listener.cc ('k') | net/http2/hpack/decoder/hpack_decoder_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698