1
#pragma once
2

            
3
#include "envoy/config/typed_config.h"
4
#include "envoy/stream_info/filter_state.h"
5

            
6
#include "source/common/common/logger.h"
7

            
8
#include "absl/strings/string_view.h"
9

            
10
namespace Envoy {
11
namespace Router {
12

            
13
/**
14
 * Used to decide if an internal redirect is allowed to be followed based on the target route.
15
 * Subclassing Logger::Loggable so that implementations can log details.
16
 */
17
class InternalRedirectPredicate : Logger::Loggable<Logger::Id::router> {
18
public:
19
41
  virtual ~InternalRedirectPredicate() = default;
20

            
21
  /**
22
   * A FilterState is provided so that predicate implementation can use it to preserve state across
23
   * internal redirects.
24
   * @param filter_state supplies the filter state associated with the current request so that the
25
   *        predicates can use it to persist states across filter chains.
26
   * @param target_route_name indicates the route that an internal redirect is targeting.
27
   * @param downstream_is_https indicates the downstream request is using https.
28
   * @param target_is_https indicates the internal redirect target url has https in the url.
29
   * @return whether the route specified by target_route_name is allowed to be followed. Any
30
   *         predicate returning false will prevent the redirect from being followed, causing the
31
   *         response to be proxied downstream.
32
   */
33
  virtual bool acceptTargetRoute(StreamInfo::FilterState& filter_state,
34
                                 absl::string_view target_route_name, bool downstream_is_https,
35
                                 bool target_is_https) PURE;
36

            
37
  /**
38
   * @return the name of the current predicate.
39
   */
40
  virtual absl::string_view name() const PURE;
41
};
42

            
43
using InternalRedirectPredicateSharedPtr = std::shared_ptr<InternalRedirectPredicate>;
44

            
45
/**
46
 * Factory for InternalRedirectPredicate.
47
 */
48
class InternalRedirectPredicateFactory : public Config::TypedFactory {
49
public:
50
  ~InternalRedirectPredicateFactory() override = default;
51

            
52
  /**
53
   * @param config contains the proto stored in TypedExtensionConfig.typed_config for the predicate.
54
   * @param current_route_name stores the route name of the route where the predicate is installed.
55
   * @return an InternalRedirectPredicate. The given current_route_name is useful for predicates
56
   *         that need to create per-route FilterState.
57
   */
58
  virtual InternalRedirectPredicateSharedPtr
59
  createInternalRedirectPredicate(const Protobuf::Message& config,
60
                                  absl::string_view current_route_name) PURE;
61

            
62
18
  std::string category() const override { return "envoy.internal_redirect_predicates"; }
63
};
64

            
65
} // namespace Router
66
} // namespace Envoy