syntax = "proto3";

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

import "envoy/config/common/mutation_rules/v3/mutation_rules.proto";
import "envoy/config/core/v3/base.proto";

import "udpa/annotations/status.proto";

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

// [#protodoc-title: Header mutation filter configuration]
// Mutate HTTP headers and trailers in requests and responses.
// [#extension: envoy.filters.http.header_mutation]

// [#next-free-field: 6]
message Mutations {
  // The request mutations are applied before the request is forwarded to the upstream cluster.
  repeated config.common.mutation_rules.v3.HeaderMutation request_mutations = 1;

  // The ``path`` header query parameter mutations are applied after ``request_mutations`` and before the request
  // is forwarded to the next filter in the filter chain.
  repeated config.core.v3.KeyValueMutation query_parameter_mutations = 3;

  // The response mutations are applied before the response is sent to the downstream client.
  repeated config.common.mutation_rules.v3.HeaderMutation response_mutations = 2;

  // The response trailer mutations are applied before the response is sent to the downstream client.
  repeated config.common.mutation_rules.v3.HeaderMutation response_trailers_mutations = 4;

  // The request trailer mutations are applied before the request is sent to the upstream cluster.
  repeated config.common.mutation_rules.v3.HeaderMutation request_trailers_mutations = 5;
}

// Per route configuration for the header mutation filter.
message HeaderMutationPerRoute {
  Mutations mutations = 1;
}

// Configuration for the header mutation filter. The mutation rules in the filter configuration will
// always be applied first and then the per-route mutation rules, if both are specified.
message HeaderMutation {
  Mutations mutations = 1;

  // If per route HeaderMutationPerRoute config is configured at multiple route levels, header mutations
  // at all specified levels are evaluated. By default, the order is from most specific (i.e. route entry level)
  // to least specific (i.e. route configuration level). Later header mutations may override earlier mutations.
  //
  // This order can be reversed by setting this field to true. In other words, most specific level mutation
  // is evaluated last.
  bool most_specific_header_mutations_wins = 2;
}
