Add checked accessors for strings, tokens, and byte sequences As part of the migration off the existing GetString method, which works for all three of those item types. PiperOrigin-RevId: 962357666
diff --git a/quiche/common/structured_headers.h b/quiche/common/structured_headers.h index f715f7f..d23fe72 100644 --- a/quiche/common/structured_headers.h +++ b/quiche/common/structured_headers.h
@@ -104,6 +104,24 @@ QUICHE_CHECK(value); return *value; } + // TODO(apaseltiner): Rename this to `GetString()` after all callers have been + // migrated off the current version of `GetString()` that works with strings, + // tokens, and byte sequences. + const std::string& GetStringStrict() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + const auto* value = GetIfString(); + QUICHE_CHECK(value); + return *value; + } + const std::string& GetToken() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + const auto* value = GetIfToken(); + QUICHE_CHECK(value); + return *value; + } + const std::string& GetByteSequence() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + const auto* value = GetIfByteSequence(); + QUICHE_CHECK(value); + return *value; + } const int64_t* GetIfInteger() const ABSL_ATTRIBUTE_LIFETIME_BOUND; int64_t* GetIfInteger() ABSL_ATTRIBUTE_LIFETIME_BOUND; @@ -125,8 +143,8 @@ const bool* GetIfBoolean() const ABSL_ATTRIBUTE_LIFETIME_BOUND; bool* GetIfBoolean() ABSL_ATTRIBUTE_LIFETIME_BOUND; - // Deprecated: Prefer `GetIfString()`, `GetIfToken()`, or - // `GetIfByteSequence()`. + // Deprecated: Prefer `GetStringStrict()`, `GetToken()`, or + // `GetByteSequence()`. const std::string& GetString() const { struct Visitor { const std::string* operator()(const std::monostate&) { return nullptr; }