1
#include "source/common/router/header_cluster_specifier.h"
2

            
3
#include "source/common/router/delegating_route_impl.h"
4

            
5
namespace Envoy {
6
namespace Router {
7

            
8
HeaderClusterSpecifierPlugin::HeaderClusterSpecifierPlugin(absl::string_view cluster_header)
9
127
    : cluster_header_(cluster_header) {}
10

            
11
RouteConstSharedPtr HeaderClusterSpecifierPlugin::route(RouteEntryAndRouteConstSharedPtr parent,
12
                                                        const Http::RequestHeaderMap& headers,
13
                                                        const StreamInfo::StreamInfo&,
14
172
                                                        uint64_t) const {
15

            
16
172
  const auto entry = headers.get(cluster_header_);
17
172
  absl::string_view cluster_name;
18
172
  if (!entry.empty()) {
19
    // This is an implicitly untrusted header, so per the API documentation only
20
    // the first value is used.
21
169
    cluster_name = entry[0]->value().getStringView();
22
169
  }
23
172
  return std::make_shared<DynamicRouteEntry>(std::move(parent), std::string(cluster_name));
24
172
}
25

            
26
} // namespace Router
27
} // namespace Envoy