Related Documentation
Incompatible with
on-prem
Related Resources

The Modify Headers policy can set or remove headers on requests.

Use cases

Common use cases for the Modify Headers policy:

Use case

Description

Remove and replace a header Remove a specific header and replace it with a custom header of your choice.
Add a header based on a condition If a record fits a specific condition, add a custom header of your choice.

How it works

This policy runs in the produce or consume phase.

For produced messages:

  1. A Kafka client produces messages and sends them to Event Gateway.
  2. Event Gateway adjusts the headers before passing messages to the broker.

For consumed messages:

  1. Event Gateway consumes messages from a Kafka broker.
  2. Event Gateway adjusts the headers before passing messages to the client.
 
sequenceDiagram
  autonumber
  participant client as Client
  participant egw as Event Gateway
  participant broker as Event broker

  client->>egw: produce message
  egw->>egw: remove or add headers
  
  egw->>broker: send message

  broker->>egw: consume message
  egw->>egw: remove or add headers

  egw->>client: pass message with new headers

  

Nested policies

This policy can be applied directly to the virtual cluster, or be nested within a Schema Validation policy. See the policy nesting example to learn how to apply a Modify Headers policy to a parent.

Nested policies are sorted into an index. You can re-order nested policies within the parent policy by adjusting this index. See the reference for nested policies for more detail.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!