Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/source/common/http/hash_policy.h
Line
Count
Source
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
9
namespace Regex {
10
class Engine;
11
}
12
13
namespace Http {
14
15
/**
16
 * Implementation of HashPolicy that reads from the proto route config.
17
 */
18
class HashPolicyImpl : public HashPolicy {
19
public:
20
  explicit HashPolicyImpl(
21
      absl::Span<const envoy::config::route::v3::RouteAction::HashPolicy* const> hash_policy,
22
      Regex::Engine& regex_engine);
23
24
  // Http::HashPolicy
25
  absl::optional<uint64_t>
26
  generateHash(const Network::Address::Instance* downstream_addr, const RequestHeaderMap& headers,
27
               const AddCookieCallback add_cookie,
28
               const StreamInfo::FilterStateSharedPtr filter_state) const override;
29
30
  class HashMethod {
31
  public:
32
11.9k
    virtual ~HashMethod() = default;
33
    virtual absl::optional<uint64_t>
34
    evaluate(const Network::Address::Instance* downstream_addr, const RequestHeaderMap& headers,
35
             const AddCookieCallback add_cookie,
36
             const StreamInfo::FilterStateSharedPtr filter_state) const PURE;
37
38
    // If the method is a terminal method, ignore rest of the hash policy chain.
39
    virtual bool terminal() const PURE;
40
  };
41
42
  using HashMethodPtr = std::unique_ptr<HashMethod>;
43
44
private:
45
  std::vector<HashMethodPtr> hash_impls_;
46
};
47
48
} // namespace Http
49
} // namespace Envoy