Convert HttpValidationPolicy to a struct. Envoy needs a policy different from `enforce_all_ == true` or `enforce_all_ == false`. A struct allows for more explicit customization. Also remove quiche::HttpValidationPolicy::CreateDefault() for brevity. PiperOrigin-RevId: 505193270
diff --git a/build/source_list.bzl b/build/source_list.bzl index 4d0a1fd..e8b4451 100644 --- a/build/source_list.bzl +++ b/build/source_list.bzl
@@ -408,7 +408,6 @@ "balsa/balsa_frame.cc", "balsa/balsa_headers.cc", "balsa/header_properties.cc", - "balsa/http_validation_policy.cc", "balsa/simple_buffer.cc", "balsa/standard_header_map.cc", "common/capsule.cc",
diff --git a/build/source_list.gni b/build/source_list.gni index 445844a..da3d5f0 100644 --- a/build/source_list.gni +++ b/build/source_list.gni
@@ -408,7 +408,6 @@ "src/quiche/balsa/balsa_frame.cc", "src/quiche/balsa/balsa_headers.cc", "src/quiche/balsa/header_properties.cc", - "src/quiche/balsa/http_validation_policy.cc", "src/quiche/balsa/simple_buffer.cc", "src/quiche/balsa/standard_header_map.cc", "src/quiche/common/capsule.cc",
diff --git a/build/source_list.json b/build/source_list.json index d03d722..04319c6 100644 --- a/build/source_list.json +++ b/build/source_list.json
@@ -407,7 +407,6 @@ "quiche/balsa/balsa_frame.cc", "quiche/balsa/balsa_headers.cc", "quiche/balsa/header_properties.cc", - "quiche/balsa/http_validation_policy.cc", "quiche/balsa/simple_buffer.cc", "quiche/balsa/standard_header_map.cc", "quiche/common/capsule.cc",
diff --git a/quiche/balsa/balsa_frame.cc b/quiche/balsa/balsa_frame.cc index 8e693cb..5219bf3 100644 --- a/quiche/balsa/balsa_frame.cc +++ b/quiche/balsa/balsa_frame.cc
@@ -350,7 +350,7 @@ // https://tools.ietf.org/html/rfc7230#section-3.2.4 says that a proxy // can choose to reject or normalize continuation lines. if ((c != ' ' && c != '\t') || - http_validation_policy().disallow_header_continuation_lines()) { + http_validation_policy().disallow_header_continuation_lines) { HandleError(is_trailer ? BalsaFrameEnums::INVALID_TRAILER_FORMAT : BalsaFrameEnums::INVALID_HEADER_FORMAT); return false; @@ -384,7 +384,7 @@ line_begin - stream_begin, line_end - stream_begin, line_end - stream_begin, line_end - stream_begin, 0)); if (current >= line_end) { - if (http_validation_policy().require_header_colon()) { + if (http_validation_policy().require_header_colon) { HandleError(is_trailer ? BalsaFrameEnums::TRAILER_MISSING_COLON : BalsaFrameEnums::HEADER_MISSING_COLON); return false; @@ -424,7 +424,7 @@ // construct which is technically not allowed by the spec. // In strict mode, we do treat this invalid value-less key as an error. - if (http_validation_policy().require_header_colon()) { + if (http_validation_policy().require_header_colon) { HandleError(is_trailer ? BalsaFrameEnums::TRAILER_MISSING_COLON : BalsaFrameEnums::HEADER_MISSING_COLON); return false; @@ -624,7 +624,7 @@ if ((headers->content_length_status_ != content_length_status) || ((headers->content_length_status_ == BalsaHeadersEnums::VALID_CONTENT_LENGTH) && - (http_validation_policy().disallow_multiple_content_length() || + (http_validation_policy().disallow_multiple_content_length || length != headers->content_length_))) { HandleError(BalsaFrameEnums::MULTIPLE_CONTENT_LENGTH_KEYS); return; @@ -642,7 +642,7 @@ if (!is_trailer) { if (http_validation_policy() - .disallow_transfer_encoding_with_content_length() && + .disallow_transfer_encoding_with_content_length && content_length_idx != 0 && transfer_encoding_idx != 0) { HandleError(BalsaFrameEnums::BOTH_TRANSFER_ENCODING_AND_CONTENT_LENGTH); return;
diff --git a/quiche/balsa/balsa_frame.h b/quiche/balsa/balsa_frame.h index a698298..7dd3214 100644 --- a/quiche/balsa/balsa_frame.h +++ b/quiche/balsa/balsa_frame.h
@@ -68,8 +68,7 @@ start_of_trailer_line_(0), trailer_length_(0), trailer_(nullptr), - invalid_chars_level_(InvalidCharsLevel::kOff), - http_validation_policy_(HttpValidationPolicy::CreateDefault()) {} + invalid_chars_level_(InvalidCharsLevel::kOff) {} ~BalsaFrame() override {}
diff --git a/quiche/balsa/balsa_frame_test.cc b/quiche/balsa/balsa_frame_test.cc index 4b8f365..d89816b 100644 --- a/quiche/balsa/balsa_frame_test.cc +++ b/quiche/balsa/balsa_frame_test.cc
@@ -576,8 +576,6 @@ class HTTPBalsaFrameTest : public QuicheTest { protected: void SetUp() override { - balsa_frame_.set_http_validation_policy( - HttpValidationPolicy::CreateDefault()); balsa_frame_.set_balsa_headers(&headers_); balsa_frame_.set_balsa_trailer(&trailer_); balsa_frame_.set_balsa_visitor(&visitor_mock_); @@ -2464,8 +2462,6 @@ class BalsaFrameParsingTest : public QuicheTest { protected: void SetUp() override { - balsa_frame_.set_http_validation_policy( - HttpValidationPolicy::CreateDefault()); balsa_frame_.set_is_request(true); balsa_frame_.set_balsa_headers(&headers_); balsa_frame_.set_balsa_visitor(&visitor_mock_);
diff --git a/quiche/balsa/http_validation_policy.cc b/quiche/balsa/http_validation_policy.cc deleted file mode 100644 index 5aab23b..0000000 --- a/quiche/balsa/http_validation_policy.cc +++ /dev/null
@@ -1,24 +0,0 @@ -// Copyright 2022 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. - -#include "quiche/balsa/http_validation_policy.h" - -#include <tuple> - -#include "quiche/common/platform/api/quiche_logging.h" - -namespace quiche { - -HttpValidationPolicy::HttpValidationPolicy(bool enforce_all) - : enforce_all_(enforce_all) {} - -HttpValidationPolicy HttpValidationPolicy::CreateDefault() { - return HttpValidationPolicy(false); -} - -bool HttpValidationPolicy::operator==(const HttpValidationPolicy& other) const { - return enforce_all_ == other.enforce_all_; -} - -} // namespace quiche
diff --git a/quiche/balsa/http_validation_policy.h b/quiche/balsa/http_validation_policy.h index 89926c6..725f48e 100644 --- a/quiche/balsa/http_validation_policy.h +++ b/quiche/balsa/http_validation_policy.h
@@ -12,42 +12,23 @@ namespace quiche { // An HttpValidationPolicy captures policy choices affecting parsing of HTTP -// requests. It offers individual Boolean member functions to be consulted -// during the parsing of an HTTP request. -class QUICHE_EXPORT HttpValidationPolicy { - public: - HttpValidationPolicy(bool enforce_all); - - static HttpValidationPolicy CreateDefault(); - +// requests. It offers individual Boolean members to be consulted during the +// parsing of an HTTP request. +struct QUICHE_EXPORT HttpValidationPolicy { // https://tools.ietf.org/html/rfc7230#section-3.2.4 deprecates "folding" // of long header lines onto continuation lines. - bool disallow_header_continuation_lines() const { return enforce_all_; } + bool disallow_header_continuation_lines = false; // A valid header line requires a header name and a colon. - bool require_header_colon() const { return enforce_all_; } + bool require_header_colon = false; // https://tools.ietf.org/html/rfc7230#section-3.3.2 disallows multiple // Content-Length header fields with the same value. - bool disallow_multiple_content_length() const { return enforce_all_; } + bool disallow_multiple_content_length = false; // https://tools.ietf.org/html/rfc7230#section-3.3.2 disallows // Transfer-Encoding and Content-Length header fields together. - bool disallow_transfer_encoding_with_content_length() const { - return enforce_all_; - } - - bool operator==(const HttpValidationPolicy& other) const; - - friend QUICHE_EXPORT std::ostream& operator<<( - std::ostream& os, const HttpValidationPolicy& policy) { - os << "HttpValidationPolicy(enforce_all_=" << policy.enforce_all_ << ")"; - return os; - } - - private: - // Enforce "everything": set for strictest possible parsing. - bool enforce_all_; + bool disallow_transfer_encoding_with_content_length = false; }; } // namespace quiche