Skip to content

Commit

Permalink
router: removing an exception
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <[email protected]>
  • Loading branch information
alyssawilk committed Sep 11, 2024
1 parent cd3346d commit e6694cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
24 changes: 18 additions & 6 deletions source/common/router/config_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,19 @@ 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 +407,8 @@ 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 +571,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,11 +1198,11 @@ 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(),
return InternalRedirectPolicyImpl::create(route_config.internal_redirect_policy(),
validator, current_route_name);
}
envoy::config::route::v3::InternalRedirectPolicy policy_config;
Expand All @@ -1205,7 +1217,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
13 changes: 9 additions & 4 deletions source/common/router/config_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,12 @@ 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 +621,10 @@ 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 +1180,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

0 comments on commit e6694cc

Please sign in to comment.