Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router: removing an exception #35605

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions source/common/router/config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,20 @@ Upstream::RetryPrioritySharedPtr RetryPolicyImpl::retryPriority() const {
*validation_visitor_, num_retries_);
}

absl::StatusOr<std::unique_ptr<InternalRedirectPolicyImpl>> InternalRedirectPolicyImpl::create(
const envoy::config::route::v3::InternalRedirectPolicy& policy_config,
ProtobufMessage::ValidationVisitor& validator, absl::string_view current_route_name) {
absl::Status creation_status = absl::OkStatus();
auto ret = std::unique_ptr<InternalRedirectPolicyImpl>(new InternalRedirectPolicyImpl(
policy_config, validator, current_route_name, creation_status));
RETURN_IF_NOT_OK(creation_status);
return ret;
}

InternalRedirectPolicyImpl::InternalRedirectPolicyImpl(
const envoy::config::route::v3::InternalRedirectPolicy& policy_config,
ProtobufMessage::ValidationVisitor& validator, absl::string_view current_route_name)
ProtobufMessage::ValidationVisitor& validator, absl::string_view current_route_name,
absl::Status& creation_status)
: current_route_name_(current_route_name),
redirect_response_codes_(buildRedirectResponseCodes(policy_config)),
max_internal_redirects_(
Expand All @@ -397,7 +408,9 @@ InternalRedirectPolicyImpl::InternalRedirectPolicyImpl(
}
for (const auto& header : policy_config.response_headers_to_copy()) {
if (!Http::HeaderUtility::isModifiableHeader(header)) {
throwEnvoyExceptionOrPanic(":-prefixed headers or Hosts may not be specified here.");
creation_status =
absl::InvalidArgumentError(":-prefixed headers or Hosts may not be specified here.");
return;
}
response_headers_to_copy_.emplace_back(header);
}
Expand Down Expand Up @@ -560,7 +573,8 @@ RouteEntryImplBase::RouteEntryImplBase(const CommonVirtualHostSharedPtr& vhost,
: nullptr),
hedge_policy_(buildHedgePolicy(vhost->hedgePolicy(), route.route())),
internal_redirect_policy_(
buildInternalRedirectPolicy(route.route(), validator, route.name())),
THROW_OR_RETURN_VALUE(buildInternalRedirectPolicy(route.route(), validator, route.name()),
std::unique_ptr<InternalRedirectPolicyImpl>)),
config_headers_(
Http::HeaderUtility::buildHeaderDataVector(route.match().headers(), factory_context)),
dynamic_metadata_([&]() {
Expand Down Expand Up @@ -1186,12 +1200,13 @@ absl::StatusOr<std::unique_ptr<RetryPolicyImpl>> RouteEntryImplBase::buildRetryP
return nullptr;
}

std::unique_ptr<InternalRedirectPolicyImpl> RouteEntryImplBase::buildInternalRedirectPolicy(
absl::StatusOr<std::unique_ptr<InternalRedirectPolicyImpl>>
RouteEntryImplBase::buildInternalRedirectPolicy(
const envoy::config::route::v3::RouteAction& route_config,
ProtobufMessage::ValidationVisitor& validator, absl::string_view current_route_name) const {
if (route_config.has_internal_redirect_policy()) {
return std::make_unique<InternalRedirectPolicyImpl>(route_config.internal_redirect_policy(),
validator, current_route_name);
return InternalRedirectPolicyImpl::create(route_config.internal_redirect_policy(), validator,
current_route_name);
}
envoy::config::route::v3::InternalRedirectPolicy policy_config;
switch (route_config.internal_redirect_action()) {
Expand All @@ -1205,7 +1220,7 @@ std::unique_ptr<InternalRedirectPolicyImpl> RouteEntryImplBase::buildInternalRed
if (route_config.has_max_internal_redirects()) {
*policy_config.mutable_max_internal_redirects() = route_config.max_internal_redirects();
}
return std::make_unique<InternalRedirectPolicyImpl>(policy_config, validator, current_route_name);
return InternalRedirectPolicyImpl::create(policy_config, validator, current_route_name);
}

RouteEntryImplBase::OptionalTimeouts RouteEntryImplBase::buildOptionalTimeouts(
Expand Down
11 changes: 7 additions & 4 deletions source/common/router/config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,11 @@ class RouteTracingImpl : public RouteTracing {
*/
class InternalRedirectPolicyImpl : public InternalRedirectPolicy {
public:
static absl::StatusOr<std::unique_ptr<InternalRedirectPolicyImpl>>
create(const envoy::config::route::v3::InternalRedirectPolicy& policy_config,
ProtobufMessage::ValidationVisitor& validator, absl::string_view current_route_name);
// Constructor that enables internal redirect with policy_config controlling the configurable
// behaviors.
InternalRedirectPolicyImpl(const envoy::config::route::v3::InternalRedirectPolicy& policy_config,
ProtobufMessage::ValidationVisitor& validator,
absl::string_view current_route_name);
// Default constructor that disables internal redirect.
InternalRedirectPolicyImpl() = default;

Expand All @@ -620,6 +620,9 @@ class InternalRedirectPolicyImpl : public InternalRedirectPolicy {
bool isCrossSchemeRedirectAllowed() const override { return allow_cross_scheme_redirect_; }

private:
InternalRedirectPolicyImpl(const envoy::config::route::v3::InternalRedirectPolicy& policy_config,
ProtobufMessage::ValidationVisitor& validator,
absl::string_view current_route_name, absl::Status& creation_status);
absl::flat_hash_set<Http::Code> buildRedirectResponseCodes(
const envoy::config::route::v3::InternalRedirectPolicy& policy_config) const;

Expand Down Expand Up @@ -1175,7 +1178,7 @@ class RouteEntryImplBase : public RouteEntryAndRoute,
ProtobufMessage::ValidationVisitor& validation_visitor,
Server::Configuration::ServerFactoryContext& factory_context) const;

std::unique_ptr<InternalRedirectPolicyImpl>
absl::StatusOr<std::unique_ptr<InternalRedirectPolicyImpl>>
buildInternalRedirectPolicy(const envoy::config::route::v3::RouteAction& route_config,
ProtobufMessage::ValidationVisitor& validator,
absl::string_view current_route_name) const;
Expand Down