Line data Source code
1 : #pragma once 2 : 3 : #include <memory> 4 : #include <string> 5 : 6 : #include "envoy/common/pure.h" 7 : #include "envoy/config/typed_config.h" 8 : #include "envoy/http/header_map.h" 9 : #include "envoy/server/factory_context.h" 10 : #include "envoy/upstream/upstream.h" 11 : 12 : namespace Envoy { 13 : namespace Http { 14 : 15 : /** 16 : * Interface class for session state. Session state is used to get address of upstream host 17 : * assigned to the session. 18 : */ 19 : class SessionState { 20 : public: 21 0 : virtual ~SessionState() = default; 22 : 23 : /** 24 : * Get address of upstream host that the current session stuck on. 25 : * 26 : * @return absl::optional<absl::string_view> optional upstream address. If there is no available 27 : * session or no available address, absl::nullopt will be returned. 28 : */ 29 : virtual absl::optional<absl::string_view> upstreamAddress() const PURE; 30 : 31 : /** 32 : * Called when a request is completed to update the session state. 33 : * 34 : * @param host the upstream host that was finally selected. 35 : * @param headers the response headers. 36 : */ 37 : virtual void onUpdate(const Upstream::HostDescription& host, ResponseHeaderMap& headers) PURE; 38 : }; 39 : 40 : using SessionStatePtr = std::unique_ptr<SessionState>; 41 : 42 : /** 43 : * Interface class for creating session state from request headers. 44 : */ 45 : class SessionStateFactory { 46 : public: 47 2 : virtual ~SessionStateFactory() = default; 48 : 49 : /** 50 : * Create session state from request headers. 51 : * 52 : * @param headers request headers. 53 : */ 54 : virtual SessionStatePtr create(const RequestHeaderMap& headers) const PURE; 55 : }; 56 : 57 : using SessionStateFactorySharedPtr = std::shared_ptr<SessionStateFactory>; 58 : 59 : /* 60 : * Extension configuration for session state factory. 61 : */ 62 : class SessionStateFactoryConfig : public Envoy::Config::TypedFactory { 63 : public: 64 0 : ~SessionStateFactoryConfig() override = default; 65 : 66 : /** 67 : * Creates a particular session state factory implementation. 68 : * 69 : * @param config supplies the configuration for the session state factory extension. 70 : * @param context supplies the factory context. Please don't store the reference to 71 : * the context as it is only valid during the call. 72 : * @return SessionStateFactorySharedPtr the session state factory. 73 : */ 74 : virtual SessionStateFactorySharedPtr 75 : createSessionStateFactory(const Protobuf::Message& config, 76 : Server::Configuration::GenericFactoryContext& context) PURE; 77 : 78 6 : std::string category() const override { return "envoy.http.stateful_session"; } 79 : }; 80 : 81 : using SessionStateFactoryConfigPtr = std::unique_ptr<SessionStateFactoryConfig>; 82 : 83 : } // namespace Http 84 : } // namespace Envoy