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

Unified Diff: net/spdy/hpack/hpack_decoder3.h

Issue 2644683002: Add HpackDecoder3, an adapter using HpackDecoder (in net/http2/hpack/decoder). (Closed)
Patch Set: Nits. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/hpack/hpack_decoder2_test.cc ('k') | net/spdy/hpack/hpack_decoder3.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/hpack/hpack_decoder3.h
diff --git a/net/spdy/hpack/hpack_decoder3.h b/net/spdy/hpack/hpack_decoder3.h
new file mode 100644
index 0000000000000000000000000000000000000000..6203dfd322b00fc23d9588a401f858b993bb0748
--- /dev/null
+++ b/net/spdy/hpack/hpack_decoder3.h
@@ -0,0 +1,112 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_SPDY_HPACK_HPACK_DECODER3_H_
+#define NET_SPDY_HPACK_HPACK_DECODER3_H_
+
+// HpackDecoder3 implements HpackDecoderInterface, using Http2HpackDecoder to
+// decode HPACK blocks into HTTP/2 header lists as outlined in
+// http://tools.ietf.org/html/rfc7541.
+
+#include <stddef.h>
+
+#include <memory>
+
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+#include "net/base/net_export.h"
+#include "net/http2/hpack/decoder/hpack_decoder_listener.h"
+#include "net/http2/hpack/decoder/http2_hpack_decoder.h"
+#include "net/http2/hpack/hpack_string.h"
+#include "net/http2/hpack/http2_hpack_constants.h"
+#include "net/spdy/hpack/hpack_decoder_interface.h"
+#include "net/spdy/hpack/hpack_header_table.h"
+#include "net/spdy/spdy_header_block.h"
+#include "net/spdy/spdy_headers_handler_interface.h"
+
+namespace net {
+namespace test {
+class HpackDecoder3Peer;
+} // namespace test
+
+class NET_EXPORT_PRIVATE HpackDecoder3 : public HpackDecoderInterface {
+ public:
+ friend test::HpackDecoder3Peer;
+ HpackDecoder3();
+ ~HpackDecoder3() override;
+
+ // Override the HpackDecoderInterface methods:
+
+ void ApplyHeaderTableSizeSetting(size_t size_setting) override;
+ void HandleControlFrameHeadersStart(
+ SpdyHeadersHandlerInterface* handler) override;
+ bool HandleControlFrameHeadersData(const char* headers_data,
+ size_t headers_data_length) override;
+ bool HandleControlFrameHeadersComplete(size_t* compressed_len) override;
+ const SpdyHeaderBlock& decoded_block() const override;
+ void SetHeaderTableDebugVisitor(
+ std::unique_ptr<HpackHeaderTable::DebugVisitorInterface> visitor)
+ override;
+ void set_max_decode_buffer_size_bytes(
+ size_t max_decode_buffer_size_bytes) override;
+
+ private:
+ class NET_EXPORT_PRIVATE ListenerAdapter : public HpackDecoderListener {
+ public:
+ ListenerAdapter();
+ ~ListenerAdapter() override;
+
+ // If a SpdyHeadersHandlerInterface is provided, the decoder will emit
+ // headers to it rather than accumulating them in a SpdyHeaderBlock.
+ // Does not take ownership of the handler, but does use the pointer until
+ // the current HPACK block is completely decoded.
+ void set_handler(SpdyHeadersHandlerInterface* handler);
+ const SpdyHeaderBlock& decoded_block() const { return decoded_block_; }
+
+ // Override the HpackDecoderListener methods:
+
+ void OnHeaderListStart() override;
+ void OnHeader(HpackEntryType entry_type,
+ const HpackString& name,
+ const HpackString& value) override;
+ void OnHeaderListEnd() override;
+ void OnHeaderErrorDetected(base::StringPiece error_message) override;
+
+ private:
+ // If the caller doesn't provide a handler, the header list is stored in
+ // this SpdyHeaderBlock.
+ SpdyHeaderBlock decoded_block_;
+
+ // If non-NULL, handles decoded headers. Not owned.
+ SpdyHeadersHandlerInterface* handler_;
+
+ // Total bytes of the name and value strings in the current HPACK block.
+ size_t total_uncompressed_bytes_;
+ };
+
+ // Converts calls to HpackDecoderListener into calls to
+ // SpdyHeadersHandlerInterface.
+ ListenerAdapter listener_adapter_;
+
+ // The actual decoder.
+ Http2HpackDecoder hpack_decoder_;
+
+ // Total bytes that have been received as input (i.e. HPACK encoded)
+ // in the current HPACK block.
+ size_t total_hpack_bytes_;
+
+ // How much encoded data this decoder is willing to buffer.
+ size_t max_decode_buffer_size_bytes_;
+
+ // Flag to keep track of having seen the header block start. Needed at the
+ // moment because HandleControlFrameHeadersStart won't be called if a handler
+ // is not being provided by the caller.
+ bool header_block_started_;
+
+ DISALLOW_COPY_AND_ASSIGN(HpackDecoder3);
+};
+
+} // namespace net
+
+#endif // NET_SPDY_HPACK_HPACK_DECODER3_H_
« no previous file with comments | « net/spdy/hpack/hpack_decoder2_test.cc ('k') | net/spdy/hpack/hpack_decoder3.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698