1
#pragma once
2

            
3
#include "envoy/http/header_map.h"
4
#include "envoy/stream_info/stream_info.h"
5

            
6
#include "absl/types/optional.h"
7

            
8
namespace Envoy {
9
namespace Http {
10

            
11
/**
12
 * CookieAttribute that stores the name and value of a cookie.
13
 */
14
class CookieAttribute {
15
public:
16
  std::string name_;
17
  std::string value_;
18
};
19

            
20
/**
21
 * Request hash policy. I.e., if using a hashing load balancer, how a request should be hashed onto
22
 * an upstream host.
23
 */
24
class HashPolicy {
25
public:
26
8617
  virtual ~HashPolicy() = default;
27

            
28
  /**
29
   * A callback used for requesting that a cookie be set with the given lifetime.
30
   * @param key the name of the cookie to be set
31
   * @param path the path of the cookie, or the empty string if no path should be set.
32
   * @param ttl the lifetime of the cookie
33
   * @return std::string the opaque value of the cookie that will be set
34
   */
35
  using AddCookieCallback = std::function<std::string(
36
      absl::string_view name, absl::string_view path, std::chrono::seconds ttl,
37
      absl::Span<const CookieAttribute> attributes)>;
38

            
39
  /**
40
   * @param headers stores the HTTP headers for the stream.
41
   * @param info stores the stream info for the stream.
42
   * @param add_cookie is called to add a set-cookie header on the reply sent to the downstream
43
   * host.
44
   * @return absl::optional<uint64_t> an optional hash value to route on. A hash value might not be
45
   * returned if for example the specified HTTP header does not exist.
46
   */
47
  virtual absl::optional<uint64_t> generateHash(OptRef<const RequestHeaderMap> headers,
48
                                                OptRef<const StreamInfo::StreamInfo> info,
49
                                                AddCookieCallback add_cookie = nullptr) const PURE;
50
};
51

            
52
} // namespace Http
53
} // namespace Envoy