Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/config/route/v3/route_components.pb.h" 4 : #include "envoy/http/hash_policy.h" 5 : #include "envoy/stream_info/filter_state.h" 6 : 7 : namespace Envoy { 8 : namespace Http { 9 : 10 : /** 11 : * Implementation of HashPolicy that reads from the proto route config. 12 : */ 13 : class HashPolicyImpl : public HashPolicy { 14 : public: 15 : explicit HashPolicyImpl( 16 : absl::Span<const envoy::config::route::v3::RouteAction::HashPolicy* const> hash_policy); 17 : 18 : // Http::HashPolicy 19 : absl::optional<uint64_t> 20 : generateHash(const Network::Address::Instance* downstream_addr, const RequestHeaderMap& headers, 21 : const AddCookieCallback add_cookie, 22 : const StreamInfo::FilterStateSharedPtr filter_state) const override; 23 : 24 : class HashMethod { 25 : public: 26 148 : virtual ~HashMethod() = default; 27 : virtual absl::optional<uint64_t> 28 : evaluate(const Network::Address::Instance* downstream_addr, const RequestHeaderMap& headers, 29 : const AddCookieCallback add_cookie, 30 : const StreamInfo::FilterStateSharedPtr filter_state) const PURE; 31 : 32 : // If the method is a terminal method, ignore rest of the hash policy chain. 33 : virtual bool terminal() const PURE; 34 : }; 35 : 36 : using HashMethodPtr = std::unique_ptr<HashMethod>; 37 : 38 : private: 39 : std::vector<HashMethodPtr> hash_impls_; 40 : }; 41 : 42 : } // namespace Http 43 : } // namespace Envoy