Removes ListenerAdapter::decoded_block_ and all accessors.
Also updates ListenerAdapter to verify that the passed-in headers handler is non-nullptr.
Protected by refactoring, no functional change.
PiperOrigin-RevId: 596013967
diff --git a/quiche/spdy/core/hpack/hpack_decoder_adapter.cc b/quiche/spdy/core/hpack/hpack_decoder_adapter.cc
index 31b606f..0a9b5a4 100644
--- a/quiche/spdy/core/hpack/hpack_decoder_adapter.cc
+++ b/quiche/spdy/core/hpack/hpack_decoder_adapter.cc
@@ -104,10 +104,6 @@
return true;
}
-const Http2HeaderBlock& HpackDecoderAdapter::decoded_block() const {
- return listener_adapter_.decoded_block();
-}
-
void HpackDecoderAdapter::set_max_decode_buffer_size_bytes(
size_t max_decode_buffer_size_bytes) {
QUICHE_DVLOG(2) << "HpackDecoderAdapter::set_max_decode_buffer_size_bytes";
@@ -120,11 +116,13 @@
max_header_block_bytes_ = max_header_block_bytes;
}
-HpackDecoderAdapter::ListenerAdapter::ListenerAdapter() : handler_(nullptr) {}
+HpackDecoderAdapter::ListenerAdapter::ListenerAdapter()
+ : no_op_handler_(nullptr), handler_(&no_op_handler_) {}
HpackDecoderAdapter::ListenerAdapter::~ListenerAdapter() = default;
void HpackDecoderAdapter::ListenerAdapter::set_handler(
SpdyHeadersHandlerInterface* handler) {
+ QUICHE_CHECK_NE(handler, nullptr);
handler_ = handler;
}
@@ -132,10 +130,7 @@
QUICHE_DVLOG(2) << "HpackDecoderAdapter::ListenerAdapter::OnHeaderListStart";
total_hpack_bytes_ = 0;
total_uncompressed_bytes_ = 0;
- decoded_block_.clear();
- if (handler_ != nullptr) {
- handler_->OnHeaderBlockStart();
- }
+ handler_->OnHeaderBlockStart();
}
void HpackDecoderAdapter::ListenerAdapter::OnHeader(const std::string& name,
@@ -143,23 +138,13 @@
QUICHE_DVLOG(2) << "HpackDecoderAdapter::ListenerAdapter::OnHeader:\n name: "
<< name << "\n value: " << value;
total_uncompressed_bytes_ += name.size() + value.size();
- if (handler_ == nullptr) {
- QUICHE_DVLOG(3) << "Adding to decoded_block";
- decoded_block_.AppendValueOrAddHeader(name, value);
- } else {
- QUICHE_DVLOG(3) << "Passing to handler";
- handler_->OnHeader(name, value);
- }
+ handler_->OnHeader(name, value);
}
void HpackDecoderAdapter::ListenerAdapter::OnHeaderListEnd() {
QUICHE_DVLOG(2) << "HpackDecoderAdapter::ListenerAdapter::OnHeaderListEnd";
- // We don't clear the Http2HeaderBlock here to allow access to it until the
- // next HPACK block is decoded.
- if (handler_ != nullptr) {
- handler_->OnHeaderBlockEnd(total_uncompressed_bytes_, total_hpack_bytes_);
- handler_ = nullptr;
- }
+ handler_->OnHeaderBlockEnd(total_uncompressed_bytes_, total_hpack_bytes_);
+ handler_ = &no_op_handler_;
}
void HpackDecoderAdapter::ListenerAdapter::OnHeaderErrorDetected(
diff --git a/quiche/spdy/core/hpack/hpack_decoder_adapter.h b/quiche/spdy/core/hpack/hpack_decoder_adapter.h
index ed11568..ce0f251 100644
--- a/quiche/spdy/core/hpack/hpack_decoder_adapter.h
+++ b/quiche/spdy/core/hpack/hpack_decoder_adapter.h
@@ -18,6 +18,7 @@
#include "quiche/http2/hpack/decoder/hpack_decoding_error.h"
#include "quiche/common/platform/api/quiche_export.h"
#include "quiche/spdy/core/http2_header_block.h"
+#include "quiche/spdy/core/no_op_headers_handler.h"
#include "quiche/spdy/core/spdy_headers_handler_interface.h"
namespace spdy {
@@ -39,10 +40,10 @@
// Returns the most recently applied value of SETTINGS_HEADER_TABLE_SIZE.
size_t GetCurrentHeaderTableSizeSetting() const;
- // If a SpdyHeadersHandlerInterface is provided, the decoder will emit
- // headers to it rather than accumulating them in a Http2HeaderBlock.
+ // The decoder will emit headers to the provided SpdyHeadersHandlerInterface.
// Does not take ownership of the handler, but does use the pointer until
// the current HPACK block is completely decoded.
+ // `handler` must not be nullptr.
void HandleControlFrameHeadersStart(SpdyHeadersHandlerInterface* handler);
// Called as HPACK block fragments arrive. Returns false if an error occurred
@@ -58,12 +59,6 @@
// Discards the handler supplied at the start of decoding the block.
bool HandleControlFrameHeadersComplete();
- // Accessor for the most recently decoded headers block. Valid until the next
- // call to HandleControlFrameHeadersData().
- // TODO(birenroy): Remove this method when all users of HpackDecoder specify
- // a SpdyHeadersHandlerInterface.
- const Http2HeaderBlock& decoded_block() const;
-
// Returns the current dynamic table size, including the 32 bytes per entry
// overhead mentioned in RFC 7541 section 4.1.
size_t GetDynamicTableSize() const {
@@ -93,14 +88,13 @@
ListenerAdapter();
~ListenerAdapter() override;
- // If a SpdyHeadersHandlerInterface is provided, the decoder will emit
- // headers to it rather than accumulating them in a Http2HeaderBlock.
+ // Sets the SpdyHeadersHandlerInterface to which headers are emitted.
// Does not take ownership of the handler, but does use the pointer until
// the current HPACK block is completely decoded.
+ // `handler` must not be nullptr.
void set_handler(SpdyHeadersHandlerInterface* handler);
- const Http2HeaderBlock& decoded_block() const { return decoded_block_; }
- // Override the HpackDecoderListener methods:
+ // From HpackDecoderListener
void OnHeaderListStart() override;
void OnHeader(const std::string& name, const std::string& value) override;
void OnHeaderListEnd() override;
@@ -110,11 +104,9 @@
size_t total_hpack_bytes() const { return total_hpack_bytes_; }
private:
- // If the caller doesn't provide a handler, the header list is stored in
- // this Http2HeaderBlock.
- Http2HeaderBlock decoded_block_;
+ NoOpHeadersHandler no_op_handler_;
- // If non-NULL, handles decoded headers. Not owned.
+ // Handles decoded headers.
SpdyHeadersHandlerInterface* handler_;
// Total bytes that have been received as input (i.e. HPACK encoded)