// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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;
}
