Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/common/optref.h" 4 : #include "envoy/config/typed_config.h" 5 : 6 : namespace Envoy { 7 : namespace Http { 8 : 9 : /** 10 : * Interface for generic header key formatting. 11 : */ 12 : class HeaderKeyFormatter { 13 : public: 14 0 : virtual ~HeaderKeyFormatter() = default; 15 : 16 : /** 17 : * Given an input key return the formatted key to encode. 18 : */ 19 : virtual std::string format(absl::string_view key) const PURE; 20 : }; 21 : 22 : using HeaderKeyFormatterConstPtr = std::unique_ptr<const HeaderKeyFormatter>; 23 : using HeaderKeyFormatterOptConstRef = OptRef<const HeaderKeyFormatter>; 24 : 25 : /** 26 : * Interface for header key formatters that are stateful. A formatter is created during decoding 27 : * headers, attached to the header map, and can then be used during encoding for reverse 28 : * translations if applicable. 29 : */ 30 : class StatefulHeaderKeyFormatter : public HeaderKeyFormatter { 31 : public: 32 : /** 33 : * Called for each header key received by the codec. 34 : */ 35 : virtual void processKey(absl::string_view key) PURE; 36 : 37 : /** 38 : * Called to save received reason phrase 39 : */ 40 : virtual void setReasonPhrase(absl::string_view reason_phrase) PURE; 41 : 42 : /** 43 : * Called to get saved reason phrase 44 : */ 45 : virtual absl::string_view getReasonPhrase() const PURE; 46 : }; 47 : 48 : using StatefulHeaderKeyFormatterPtr = std::unique_ptr<StatefulHeaderKeyFormatter>; 49 : using StatefulHeaderKeyFormatterOptRef = OptRef<StatefulHeaderKeyFormatter>; 50 : using StatefulHeaderKeyFormatterOptConstRef = OptRef<const StatefulHeaderKeyFormatter>; 51 : 52 : /** 53 : * Interface for creating stateful header key formatters. 54 : */ 55 : class StatefulHeaderKeyFormatterFactory { 56 : public: 57 0 : virtual ~StatefulHeaderKeyFormatterFactory() = default; 58 : 59 : /** 60 : * Create a new formatter. 61 : */ 62 : virtual StatefulHeaderKeyFormatterPtr create() PURE; 63 : }; 64 : 65 : using StatefulHeaderKeyFormatterFactorySharedPtr = 66 : std::shared_ptr<StatefulHeaderKeyFormatterFactory>; 67 : 68 : /** 69 : * Extension configuration for stateful header key formatters. 70 : */ 71 : class StatefulHeaderKeyFormatterFactoryConfig : public Config::TypedFactory { 72 : public: 73 : virtual StatefulHeaderKeyFormatterFactorySharedPtr 74 : createFromProto(const Protobuf::Message& config) PURE; 75 : 76 4 : std::string category() const override { return "envoy.http.stateful_header_formatters"; } 77 : }; 78 : 79 : } // namespace Http 80 : } // namespace Envoy