Repository: envoyproxy/envoy
File: api/envoy/config/common/mutation_rules/v3/mutation_rules.proto (Protocol Buffers)

Code before:
  // request with a 500 error. In addition, regardless of the setting of this
  // parameter, any attempt to set, add, or modify a disallowed header will
  // cause the ``rejected_header_mutations`` counter to be incremented.
  // Default is false.
  google.protobuf.BoolValue disallow_is_error = 7;
}

// The HeaderMutation structure specifies an action that may be taken on HTTP
// headers.
message HeaderMutation {
  message RemoveOnMatch {
    // A string matcher that will be applied to the header key. If the header key
    // matches, the header will be removed.
    type.matcher.v3.StringMatcher key_matcher = 1 [(validate.rules).message = {required: true}];
  }

  message RegexCopy {
    string source_header = 1
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

    string target_header = 2
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

    type.matcher.v3.RegexMatchAndSubstitute expression = 3;
  }

  oneof action {
    option (validate.required) = true;

    // Remove the specified header if it exists.
    string remove = 1
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

    // Append new header by the specified HeaderValueOption.
    core.v3.HeaderValueOption append = 2;

    // Remove the header if the key matches the specified string matcher.
    RemoveOnMatch remove_on_match = 3;

    RegexCopy regex_copy = 4;
  }
}


Review comment (refactor):
We may needn't this. We have provided regex support in the CEL, you can use CEL substitution formatter to extract something from specific attributes (like request header) as new header value. For simple example:

```
mutations
- append:
    key: something
    value: '%CEL(re.extract(request.host, '(.+?)\\\\:(\\\\d+)', '\\\\2'))%'

```

If the cel's support is not enough for you, you may could create a custom early mutation extension for this if possible.

Code after:
  // request with a 500 error. In addition, regardless of the setting of this
  // parameter, any attempt to set, add, or modify a disallowed header will
  // cause the ``rejected_header_mutations`` counter to be incremented.
  // Default is false.
  google.protobuf.BoolValue disallow_is_error = 7;
}

// The HeaderMutation structure specifies an action that may be taken on HTTP
// headers.
message HeaderMutation {
  message RemoveOnMatch {
    // A string matcher that will be applied to the header key. If the header key
    // matches, the header will be removed.
    type.matcher.v3.StringMatcher key_matcher = 1 [(validate.rules).message = {required: true}];
  }

  oneof action {
    option (validate.required) = true;

    // Remove the specified header if it exists.
    string remove = 1
        [(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

    // Append new header by the specified HeaderValueOption.
    core.v3.HeaderValueOption append = 2;

    // Remove the header if the key matches the specified string matcher.
    RemoveOnMatch remove_on_match = 3;
  }
}