Lines
100 %
Functions
#pragma once
#include <cinttypes>
#include <string>
#include <vector>
#include "envoy/config/core/v3/base.pb.h"
#include "envoy/config/route/v3/route_components.pb.h"
#include "envoy/http/codes.h"
#include "envoy/upstream/resource_manager.h"
#include "source/common/common/matchers.h"
#include "source/common/common/utility.h"
#include "source/common/http/headers.h"
#include "source/common/http/utility.h"
#include "source/common/protobuf/utility.h"
#include "absl/container/flat_hash_map.h"
#include "absl/types/optional.h"
namespace Envoy {
namespace Router {
/**
* Utility routines for loading route configuration and matching runtime request headers.
*/
class ConfigUtility {
public:
// A QueryParameterMatcher specifies one "name" or "name=value" element
// to match in a request's query string. It is the optimized, runtime
// equivalent of the QueryParameterMatcher proto in the RDS v2 API.
class QueryParameterMatcher {
QueryParameterMatcher(const envoy::config::route::v3::QueryParameterMatcher& config,
Server::Configuration::CommonFactoryContext& context);
* Check if the query parameters for a request contain a match for this
* QueryParameterMatcher.
* @param request_query_params supplies the parsed query parameters from a request.
* @return bool true if a match for this QueryParameterMatcher exists in request_query_params.
bool matches(const Http::Utility::QueryParamsMulti& request_query_params) const;
private:
const std::string name_;
const absl::optional<bool> present_match_;
const absl::optional<Matchers::StringMatcherImpl> matcher_;
};
using QueryParameterMatcherPtr = std::unique_ptr<const QueryParameterMatcher>;
// A CookieMatcher specifies match criteria for a specific cookie name parsed
// from the Cookie header.
class CookieMatcher {
CookieMatcher(const envoy::config::route::v3::CookieMatcher& config,
const std::string& name() const { return name_; }
bool matches(const absl::optional<absl::string_view>& cookie_value) const;
const bool invert_match_;
const Matchers::StringMatcherImpl string_match_;
using CookieMatcherPtr = std::unique_ptr<const CookieMatcher>;
* @return the resource priority parsed from proto.
static Upstream::ResourcePriority
parsePriority(const envoy::config::core::v3::RoutingPriority& priority);
* See if the query parameters specified in the config are present in a request.
* @param query_params supplies the query parameters from the request's query string.
* @param config_params supplies the list of configured query param conditions on which to match.
* @return bool true if all the query params (and values) in the config_params are found in the
* query_params
static bool matchQueryParams(const Http::Utility::QueryParamsMulti& query_params,
const std::vector<QueryParameterMatcherPtr>& config_query_params);
* See if the cookies specified in the config are present/matching in a request.
* @param cookies supplies the parsed cookies from the request.
* @param matchers supplies the list of configured cookie matchers on which to match.
* @return bool true if all cookie matchers succeed.
static bool matchCookies(const absl::flat_hash_map<std::string, std::string>& cookies,
const std::vector<CookieMatcherPtr>& matchers);
* Returns the redirect HTTP Status Code enum parsed from proto.
* @param code supplies the RedirectResponseCode enum.
* @return Returns the Http::Code version of the RedirectResponseCode.
static Http::Code parseRedirectResponseCode(
const envoy::config::route::v3::RedirectAction::RedirectResponseCode& code);
* Returns the HTTP Status Code enum parsed from the route's redirect or direct_response.
* @param route supplies the Route configuration.
* @return absl::optional<Http::Code> the HTTP status from the route's direct_response if
* specified, or the HTTP status code from the route's redirect if specified, or an empty
* absl::optional otherwise.
static absl::optional<Http::Code>
parseDirectResponseCode(const envoy::config::route::v3::Route& route);
* Returns the HTTP Status Code enum parsed from proto.
* @param code supplies the ClusterNotFoundResponseCode enum.
* @return Returns the Http::Code version of the ClusterNotFoundResponseCode enum.
static Http::Code parseClusterNotFoundResponseCode(
const envoy::config::route::v3::RouteAction::ClusterNotFoundResponseCode& code);
void mergeTransforms(Http::HeaderTransforms& dest, const Http::HeaderTransforms& src);
} // namespace Router
} // namespace Envoy