syntax = "proto3";

package envoy.extensions.filters.http.dynamic_forward_proxy.v3;

import "envoy/extensions/common/dynamic_forward_proxy/v3/dns_cache.proto";

import "google/protobuf/duration.proto";

import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.http.dynamic_forward_proxy.v3";
option java_outer_classname = "DynamicForwardProxyProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/dynamic_forward_proxy/v3;dynamic_forward_proxyv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Dynamic forward proxy]

// Configuration for the dynamic forward proxy HTTP filter. See the :ref:`architecture overview
// <arch_overview_http_dynamic_forward_proxy>` for more information.
// [#extension: envoy.filters.http.dynamic_forward_proxy]
message FilterConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.http.dynamic_forward_proxy.v2alpha.FilterConfig";

  oneof implementation_specifier {
    // The DNS cache configuration that the filter will attach to. Note this configuration must
    // match that of associated :ref:`dynamic forward proxy cluster configuration
    // <envoy_v3_api_field_extensions.clusters.dynamic_forward_proxy.v3.ClusterConfig.dns_cache_config>`.
    common.dynamic_forward_proxy.v3.DnsCacheConfig dns_cache_config = 1;

    // The configuration that the filter will use, when the related dynamic forward proxy cluster enabled
    // sub clusters.
    SubClusterConfig sub_cluster_config = 3;
  }

  // When this flag is set, the filter will add the resolved upstream address in the filter
  // state. The state should be saved with key
  // ``envoy.stream.upstream_address`` (See
  // :repo:`upstream_address.h<source/common/stream_info/upstream_address.h>`).
  bool save_upstream_address = 2;
}

// Per route Configuration for the dynamic forward proxy HTTP filter.
message PerRouteConfig {
  option (udpa.annotations.versioning).previous_message_type =
      "envoy.config.filter.http.dynamic_forward_proxy.v2alpha.PerRouteConfig";

  oneof host_rewrite_specifier {
    // Indicates that before DNS lookup, the host header will be swapped with
    // this value. If not set or empty, the original host header value
    // will be used and no rewrite will happen.
    //
    // Note: this rewrite affects both DNS lookup and host header forwarding. However, this
    // option shouldn't be used with
    // :ref:`HCM host rewrite <envoy_v3_api_field_config.route.v3.RouteAction.host_rewrite_literal>` given that the
    // value set here would be used for DNS lookups whereas the value set in the HCM would be used
    // for host header forwarding which is not the desired outcome.
    string host_rewrite_literal = 1;

    // Indicates that before DNS lookup, the host header will be swapped with
    // the value of this header. If not set or empty, the original host header
    // value will be used and no rewrite will happen.
    //
    // Note: this rewrite affects both DNS lookup and host header forwarding. However, this
    // option shouldn't be used with
    // :ref:`HCM host rewrite header <envoy_v3_api_field_config.route.v3.RouteAction.auto_host_rewrite>`
    // given that the value set here would be used for DNS lookups whereas the value set in the HCM
    // would be used for host header forwarding which is not the desired outcome.
    //
    // .. note::
    //
    //   If the header appears multiple times only the first value is used.
    string host_rewrite_header = 2;
  }
}

message SubClusterConfig {
  // The timeout used for sub cluster initialization. Defaults to 5s if not set.
  google.protobuf.Duration cluster_init_timeout = 3 [(validate.rules).duration = {gt {}}];
}
