1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
//
//
// Copyright 2021 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
#ifndef GRPC_SRC_CORE_EXT_XDS_XDS_ROUTING_H
#define GRPC_SRC_CORE_EXT_XDS_XDS_ROUTING_H
#include <grpc/support/port_platform.h>
#include <stddef.h>
#include <map>
#include <util/generic/string.h>
#include <util/string/cast.h>
#include <vector>
#include "y_absl/status/statusor.h"
#include "y_absl/strings/string_view.h"
#include "y_absl/types/optional.h"
#include "src/core/ext/xds/xds_http_filters.h"
#include "src/core/ext/xds/xds_listener.h"
#include "src/core/ext/xds/xds_route_config.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/transport/metadata_batch.h"
namespace grpc_core {
class XdsRouting {
public:
class VirtualHostListIterator {
public:
virtual ~VirtualHostListIterator() = default;
// Returns the number of virtual hosts in the list.
virtual size_t Size() const = 0;
// Returns the domain list for the virtual host at the specified index.
virtual const std::vector<TString>& GetDomainsForVirtualHost(
size_t index) const = 0;
};
class RouteListIterator {
public:
virtual ~RouteListIterator() = default;
// Number of routes.
virtual size_t Size() const = 0;
// Returns the matchers for the route at the specified index.
virtual const XdsRouteConfigResource::Route::Matchers& GetMatchersForRoute(
size_t index) const = 0;
};
// Returns the index of the selected virtual host in the list.
static y_absl::optional<size_t> FindVirtualHostForDomain(
const VirtualHostListIterator& vhost_iterator, y_absl::string_view domain);
// Returns the index in route_list_iterator to use for a request with
// the specified path and metadata, or nullopt if no route matches.
static y_absl::optional<size_t> GetRouteForRequest(
const RouteListIterator& route_list_iterator, y_absl::string_view path,
grpc_metadata_batch* initial_metadata);
// Returns true if \a domain_pattern is a valid domain pattern, false
// otherwise.
static bool IsValidDomainPattern(y_absl::string_view domain_pattern);
// Returns the metadata value(s) for the specified key.
// As special cases, binary headers return a value of y_absl::nullopt, and
// "content-type" header returns "application/grpc".
static y_absl::optional<y_absl::string_view> GetHeaderValue(
grpc_metadata_batch* initial_metadata, y_absl::string_view header_name,
TString* concatenated_value);
struct GeneratePerHttpFilterConfigsResult {
// Map of service config field name to list of elements for that field.
std::map<TString, std::vector<TString>> per_filter_configs;
ChannelArgs args;
};
// Generates a map of per_filter_configs. \a args is consumed.
static y_absl::StatusOr<GeneratePerHttpFilterConfigsResult>
GeneratePerHTTPFilterConfigs(
const XdsHttpFilterRegistry& http_filter_registry,
const std::vector<XdsListenerResource::HttpConnectionManager::HttpFilter>&
http_filters,
const XdsRouteConfigResource::VirtualHost& vhost,
const XdsRouteConfigResource::Route& route,
const XdsRouteConfigResource::Route::RouteAction::ClusterWeight*
cluster_weight,
const ChannelArgs& args);
};
} // namespace grpc_core
#endif // GRPC_SRC_CORE_EXT_XDS_XDS_ROUTING_H
|