Repository: envoyproxy/envoy
File: source/extensions/filters/common/ext_authz/ext_authz_http_impl.cc (C++)

Code before:
    : client_header_matchers_(toClientMatchers(
          http_service.authorization_response().allowed_client_headers(), context)),
      client_header_on_success_matchers_(toClientMatchersOnSuccess(
          http_service.authorization_response().allowed_client_headers_on_success(), context)),
      to_dynamic_metadata_matchers_(toDynamicMetadataMatchers(
          http_service.authorization_response().dynamic_metadata_from_headers(), context)),
      upstream_header_matchers_(toUpstreamMatchers(
          http_service.authorization_response().allowed_upstream_headers(), context)),
      upstream_header_to_append_matchers_(toUpstreamMatchers(
          http_service.authorization_response().allowed_upstream_headers_to_append(), context)),
      cluster_name_(http_service.server_uri().cluster()), timeout_(timeout),
      path_prefix_(
          THROW_OR_RETURN_VALUE(validatePathPrefix(http_service.path_prefix()), std::string)),
      tracing_name_(fmt::format("async {} egress", http_service.server_uri().cluster())),
      request_headers_parser_(THROW_OR_RETURN_VALUE(
          Router::HeaderParser::configure(
              http_service.authorization_request().headers_to_add(),
              envoy::config::core::v3::HeaderValueOption::OVERWRITE_IF_EXISTS_OR_ADD),
          Router::HeaderParserPtr)),
      encode_raw_headers_(encode_raw_headers),
      retry_policy_(
          http_service.has_retry_policy()
              ? absl::optional<envoy::config::route::v3::RetryPolicy>(
                    Http::Utility::convertCoreToRouteRetryPolicy(
                        http_service.retry_policy(), "5xx,gateway-error,connect-failure,reset"))
              : absl::nullopt) {}

MatcherSharedPtr
ClientConfig::toClientMatchersOnSuccess(const envoy::type::matcher::v3::ListStringMatcher& list,
                                        Server::Configuration::CommonFactoryContext& context) {
  std::vector<Matchers::StringMatcherPtr> matchers(
      CheckRequestUtils::createStringMatchers(list, context));
  return std::make_shared<HeaderKeyMatcher>(std::move(matchers));
}

MatcherSharedPtr
ClientConfig::toDynamicMetadataMatchers(const envoy::type::matcher::v3::ListStringMatcher& list,
                                        Server::Configuration::CommonFactoryContext& context) {
  std::vector<Matchers::StringMatcherPtr> matchers(
      CheckRequestUtils::createStringMatchers(list, context));
  return std::make_shared<HeaderKeyMatcher>(std::move(matchers));
}

MatcherSharedPtr
ClientConfig::toClientMatchers(const envoy::type::matcher::v3::ListStringMatcher& list,
                               Server::Configuration::CommonFactoryContext& context) {
  std::vector<Matchers::StringMatcherPtr> matchers(
      CheckRequestUtils::createStringMatchers(list, context));

  // If list is empty, all authorization response headers, except Host, should be added to
  // the client response.

Review comment (suggestion):
Sorry, may I didn't make it clear enough. I meant we can part the proto retry policy to the `RetryPolicyConstSharedPtr`. Then, we needn't to parse the proto to the retry policy implementation again and again.

Code after:
              envoy::config::core::v3::HeaderValueOption::OVERWRITE_IF_EXISTS_OR_ADD),
          Router::HeaderParserPtr)),
      encode_raw_headers_(config.encode_raw_headers()),
      retry_policy_(config.http_service().has_retry_policy()
                        ? THROW_OR_RETURN_VALUE(
                              createRetryPolicy(config.http_service().retry_policy(), context),
                              Router::RetryPolicyConstSharedPtr)
                        : nullptr) {}

ClientConfig::ClientConfig(
    const envoy::extensions::filters::http::ext_authz::v3::HttpService& http_service,
    bool encode_raw_headers, uint32_t timeout, Server::Configuration::CommonFactoryContext& context)
    : client_header_matchers_(toClientMatchers(
          http_service.authorization_response().allowed_client_headers(), context)),
      client_header_on_success_matchers_(toClientMatchersOnSuccess(
          http_service.authorization_response().allowed_client_headers_on_success(), context)),
      to_dynamic_metadata_matchers_(toDynamicMetadataMatchers(
          http_service.authorization_response().dynamic_metadata_from_headers(), context)),
      upstream_header_matchers_(toUpstreamMatchers(
          http_service.authorization_response().allowed_upstream_headers(), context)),
      upstream_header_to_append_matchers_(toUpstreamMatchers(
          http_service.authorization_response().allowed_upstream_headers_to_append(), context)),
      cluster_name_(http_service.server_uri().cluster()), timeout_(timeout),
      path_prefix_(
          THROW_OR_RETURN_VALUE(validatePathPrefix(http_service.path_prefix()), std::string)),
      tracing_name_(fmt::format("async {} egress", http_service.server_uri().cluster())),
      request_headers_parser_(THROW_OR_RETURN_VALUE(
          Router::HeaderParser::configure(
              http_service.authorization_request().headers_to_add(),
              envoy::config::core::v3::HeaderValueOption::OVERWRITE_IF_EXISTS_OR_ADD),
          Router::HeaderParserPtr)),
      encode_raw_headers_(encode_raw_headers),
      retry_policy_(
          http_service.has_retry_policy()
              ? THROW_OR_RETURN_VALUE(createRetryPolicy(http_service.retry_policy(), context),
                                      Router::RetryPolicyConstSharedPtr)
              : nullptr) {}

MatcherSharedPtr
ClientConfig::toClientMatchersOnSuccess(const envoy::type::matcher::v3::ListStringMatcher& list,
                                        Server::Configuration::CommonFactoryContext& context) {
  std::vector<Matchers::StringMatcherPtr> matchers(
      CheckRequestUtils::createStringMatchers(list, context));
  return std::make_shared<HeaderKeyMatcher>(std::move(matchers));
}

MatcherSharedPtr
ClientConfig::toDynamicMetadataMatchers(const envoy::type::matcher::v3::ListStringMatcher& list,
                                        Server::Configuration::CommonFactoryContext& context) {
  std::vector<Matchers::StringMatcherPtr> matchers(
      CheckRequestUtils::createStringMatchers(list, context));