LCOV - code coverage report
Current view: top level - envoy/http - hash_policy.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 1 4 25.0 %
Date: 2024-01-05 06:35:25 Functions: 1 4 25.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "envoy/http/header_map.h"
       4             : #include "envoy/network/address.h"
       5             : #include "envoy/stream_info/filter_state.h"
       6             : 
       7             : #include "absl/types/optional.h"
       8             : 
       9             : namespace Envoy {
      10             : namespace Http {
      11             : 
      12             : /**
      13             :  * CookieAttribute that stores the name and value of a cookie.
      14             :  */
      15             : class CookieAttribute {
      16             : public:
      17           0 :   CookieAttribute(const std::string& name, const std::string& value) : name_(name), value_(value) {}
      18             : 
      19           0 :   std::string name() const { return name_; }
      20           0 :   std::string value() const { return value_; }
      21             : 
      22             : private:
      23             :   std::string name_;
      24             :   std::string value_;
      25             : };
      26             : 
      27             : using CookieAttributeRefVector = std::vector<std::reference_wrapper<const CookieAttribute>>;
      28             : 
      29             : /**
      30             :  * Request hash policy. I.e., if using a hashing load balancer, how a request should be hashed onto
      31             :  * an upstream host.
      32             :  */
      33             : class HashPolicy {
      34             : public:
      35         223 :   virtual ~HashPolicy() = default;
      36             : 
      37             :   /**
      38             :    * A callback used for requesting that a cookie be set with the given lifetime.
      39             :    * @param key the name of the cookie to be set
      40             :    * @param path the path of the cookie, or the empty string if no path should be set.
      41             :    * @param ttl the lifetime of the cookie
      42             :    * @return std::string the opaque value of the cookie that will be set
      43             :    */
      44             :   using AddCookieCallback = std::function<std::string(
      45             :       const std::string& key, const std::string& path, std::chrono::seconds ttl,
      46             :       const CookieAttributeRefVector attributes)>;
      47             : 
      48             :   /**
      49             :    * @param downstream_address is the address of the connected client host, or nullptr if the
      50             :    * request is initiated from within this host
      51             :    * @param headers stores the HTTP headers for the stream
      52             :    * @param add_cookie is called to add a set-cookie header on the reply sent to the downstream
      53             :    * host
      54             :    * @return absl::optional<uint64_t> an optional hash value to route on. A hash value might not be
      55             :    * returned if for example the specified HTTP header does not exist.
      56             :    */
      57             :   virtual absl::optional<uint64_t>
      58             :   generateHash(const Network::Address::Instance* downstream_address,
      59             :                const RequestHeaderMap& headers, AddCookieCallback add_cookie,
      60             :                const StreamInfo::FilterStateSharedPtr filter_state) const PURE;
      61             : };
      62             : 
      63             : } // namespace Http
      64             : } // namespace Envoy

Generated by: LCOV version 1.15