1
#pragma once
2

            
3
#include "envoy/stream_info/filter_state.h"
4

            
5
namespace Envoy {
6
namespace Router {
7

            
8
/**
9
 * Configuration for debugging router behavior. The router tries to look up an instance of this
10
 * class by its `key`, in FilterState (via StreamInfo). If it's not present, debugging features are
11
 * not enabled.
12
 *
13
 * There is currently no public API for populating this configuration -- neither globally nor
14
 * per-request -- users desiring to use the router debugging features should create and install
15
 * their own custom StreamDecoderFilter to set DebugConfig as desired before the router consumes
16
 * it.
17
 *
18
 * This is intended to be temporary, and should be replaced by some proper configuration (e.g. in
19
 * router.proto) when we get unified matchers. See https://github.com/envoyproxy/envoy/issues/5569.
20
 *
21
 * TODO(mergeconflict): Keep this promise.
22
 */
23
struct DebugConfig : public StreamInfo::FilterState::Object {
24
3
  DebugConfig(bool do_not_forward) : do_not_forward_(do_not_forward) {}
25

            
26
  /**
27
   * @return the string key for finding DebugConfig, if present, in FilterState.
28
   */
29
  static absl::string_view key();
30

            
31
  /**
32
   * Do not forward the associated request to the upstream cluster, if `do_not_forward_` is true.
33
   * If the router would have forwarded it (assuming all other preconditions are met), it will
34
   * instead respond with a 204 "no content.".
35
   */
36
  bool do_not_forward_{};
37
};
38

            
39
class DebugConfigFactory : public StreamInfo::FilterState::ObjectFactory {
40
public:
41
  std::string name() const override;
42
  std::unique_ptr<StreamInfo::FilterState::Object>
43
  createFromBytes(absl::string_view data) const override;
44
};
45

            
46
} // namespace Router
47
} // namespace Envoy