Simplifies HeaderValidator error codes.
There's no difference in practice between any of the non-OK error codes.
PiperOrigin-RevId: 416328720
diff --git a/http2/adapter/header_validator.cc b/http2/adapter/header_validator.cc
index 5e8ee97..321e958 100644
--- a/http2/adapter/header_validator.cc
+++ b/http2/adapter/header_validator.cc
@@ -59,20 +59,20 @@
HeaderValidator::HeaderStatus HeaderValidator::ValidateSingleHeader(
absl::string_view key, absl::string_view value) {
if (key.empty()) {
- return HEADER_NAME_EMPTY;
+ return HEADER_FIELD_INVALID;
}
const absl::string_view validated_key = key[0] == ':' ? key.substr(1) : key;
if (validated_key.find_first_not_of(kHttp2HeaderNameAllowedChars) !=
absl::string_view::npos) {
QUICHE_VLOG(2) << "invalid chars in header name: ["
<< absl::CEscape(validated_key) << "]";
- return HEADER_NAME_INVALID_CHAR;
+ return HEADER_FIELD_INVALID;
}
if (value.find_first_not_of(kHttp2HeaderValueAllowedChars) !=
absl::string_view::npos) {
QUICHE_VLOG(2) << "invalid chars in header value: [" << absl::CEscape(value)
<< "]";
- return HEADER_VALUE_INVALID_CHAR;
+ return HEADER_FIELD_INVALID;
}
if (key[0] == ':') {
if (key == ":status") {
@@ -81,11 +81,11 @@
absl::string_view::npos) {
QUICHE_VLOG(2) << "malformed status value: [" << absl::CEscape(value)
<< "]";
- return HEADER_VALUE_INVALID_CHAR;
+ return HEADER_FIELD_INVALID;
}
if (value == "101") {
// Switching protocols is not allowed on a HTTP/2 stream.
- return HEADER_VALUE_INVALID_STATUS;
+ return HEADER_FIELD_INVALID;
}
status_ = std::string(value);
} else if (key == ":method") {
diff --git a/http2/adapter/header_validator.h b/http2/adapter/header_validator.h
index ecde204..a1d27bb 100644
--- a/http2/adapter/header_validator.h
+++ b/http2/adapter/header_validator.h
@@ -30,10 +30,7 @@
enum HeaderStatus {
HEADER_OK,
- HEADER_NAME_EMPTY,
- HEADER_NAME_INVALID_CHAR,
- HEADER_VALUE_INVALID_CHAR,
- HEADER_VALUE_INVALID_STATUS,
+ HEADER_FIELD_INVALID,
};
HeaderStatus ValidateSingleHeader(absl::string_view key,
absl::string_view value);
diff --git a/http2/adapter/header_validator_test.cc b/http2/adapter/header_validator_test.cc
index dcd92e1..35750d3 100644
--- a/http2/adapter/header_validator_test.cc
+++ b/http2/adapter/header_validator_test.cc
@@ -10,7 +10,7 @@
TEST(HeaderValidatorTest, HeaderNameEmpty) {
HeaderValidator v;
HeaderValidator::HeaderStatus status = v.ValidateSingleHeader("", "value");
- EXPECT_EQ(HeaderValidator::HEADER_NAME_EMPTY, status);
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID, status);
}
TEST(HeaderValidatorTest, HeaderValueEmpty) {
@@ -37,13 +37,13 @@
: absl::StrCat("na", c, "me");
HeaderValidator::HeaderStatus status =
v.ValidateSingleHeader(name, "value");
- EXPECT_EQ(HeaderValidator::HEADER_NAME_INVALID_CHAR, status);
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID, status);
}
// Uppercase characters in header names should not be allowed.
const std::string uc_name = is_pseudo_header ? ":Method" : "Name";
HeaderValidator::HeaderStatus status =
v.ValidateSingleHeader(uc_name, "value");
- EXPECT_EQ(HeaderValidator::HEADER_NAME_INVALID_CHAR, status);
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID, status);
}
}
@@ -60,7 +60,7 @@
for (const char* c : {"\r", "\n"}) {
HeaderValidator::HeaderStatus status =
v.ValidateSingleHeader("name", absl::StrCat("val", c, "ue"));
- EXPECT_EQ(HeaderValidator::HEADER_VALUE_INVALID_CHAR, status);
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID, status);
}
}
@@ -70,19 +70,19 @@
for (HeaderType type : {HeaderType::RESPONSE, HeaderType::RESPONSE_100}) {
// When `:status` has a non-digit value, validation will fail.
v.StartHeaderBlock();
- EXPECT_EQ(HeaderValidator::HEADER_VALUE_INVALID_CHAR,
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID,
v.ValidateSingleHeader(":status", "bar"));
EXPECT_FALSE(v.FinishHeaderBlock(type));
// When `:status` is too short, validation will fail.
v.StartHeaderBlock();
- EXPECT_EQ(HeaderValidator::HEADER_VALUE_INVALID_CHAR,
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID,
v.ValidateSingleHeader(":status", "10"));
EXPECT_FALSE(v.FinishHeaderBlock(type));
// When `:status` is too long, validation will fail.
v.StartHeaderBlock();
- EXPECT_EQ(HeaderValidator::HEADER_VALUE_INVALID_CHAR,
+ EXPECT_EQ(HeaderValidator::HEADER_FIELD_INVALID,
v.ValidateSingleHeader(":status", "9000"));
EXPECT_FALSE(v.FinishHeaderBlock(type));