1
#pragma once
2

            
3
#include <functional>
4
#include <map>
5

            
6
#include "envoy/common/pure.h"
7

            
8
#include "absl/strings/string_view.h"
9
#include "absl/types/optional.h"
10

            
11
namespace Envoy {
12
namespace Http {
13

            
14
class FilterChainFactoryCallbacks;
15

            
16
/**
17
 * This function is used to wrap the creation of an HTTP filter chain for new streams as they
18
 * come in. Filter factories create the function at configuration initialization time, and then
19
 * they are used at runtime.
20
 * @param callbacks supplies the callbacks for the stream to install filters to. Typically the
21
 * function will install a single filter, but it's technically possibly to install more than one
22
 * if desired.
23
 */
24
using FilterFactoryCb = std::function<void(FilterChainFactoryCallbacks& callbacks)>;
25

            
26
/**
27
 * Simple struct of additional contextual information of HTTP filter, e.g. filter config name
28
 * from configuration, etc.
29
 */
30
struct FilterContext {
31
1
  FilterContext() = default;
32
160280
  FilterContext(absl::string_view name) : config_name(std::string(name)) {}
33
  // The name of the filter configuration that used to create related filter factory function.
34
  // This could be any legitimate non-empty string.
35
  std::string config_name;
36
};
37

            
38
/**
39
 * A FilterChainFactory is used by a connection manager to create an HTTP level filter chain when a
40
 * new stream is created on the connection (either locally or remotely). Typically it would be
41
 * implemented by a configuration engine that would install a set of filters that are able to
42
 * process an application scenario on top of a stream.
43
 */
44
class FilterChainFactory {
45
public:
46
280519
  virtual ~FilterChainFactory() = default;
47

            
48
  /**
49
   * Called when a new HTTP stream is created on the connection.
50
   * @param callbacks supplies the callbacks that is used to create the filter chain.
51
   * @return whather a filter chain has been created.
52
   */
53
  virtual bool createFilterChain(FilterChainFactoryCallbacks& callbacks) const PURE;
54

            
55
  /**
56
   * Called when a new upgrade stream is created on the connection.
57
   * @param upgrade supplies the upgrade header from downstream
58
   * @param per_route_upgrade_map supplies the upgrade map, if any, for this route.
59
   * @param callbacks supplies the callbacks that is used to create the filter chain.
60
   * @return true if upgrades of this type are allowed and the filter chain has been created.
61
   *    returns false if this upgrade type is not configured, and no filter chain is created.
62
   */
63
  using UpgradeMap = std::map<std::string, bool>;
64
  virtual bool createUpgradeFilterChain(absl::string_view upgrade,
65
                                        const UpgradeMap* per_route_upgrade_map,
66
                                        FilterChainFactoryCallbacks& callbacks) const PURE;
67
};
68

            
69
} // namespace Http
70
} // namespace Envoy