Simple Header Policy

Description

Set and remove headers on request, response or both. The values can be literal strings, environment, system properties or request headers. Headers can be removed by simple string equality or regular expression.

Plugin

{
    "groupId": "io.apiman.plugins",
    "artifactId": "apiman-plugins-simple-header-policy",
    "version": "3.1.0-SNAPSHOT"
}

Configuration

Option Type Description Default

addHeaders

addHeaders[]

Add and overwrite headers Add headers to a request, response or both.

None

stripHeaders

stripHeaders[]

Strip headers Remove headers from a request, response or both when patterns match.

None

addHeaders

Table 1. Add headers
Option Type Description Default

headerName

String

Header Name The name of the header to set.

Empty

headerValue

String

Header Value The value of the header to set, or key into the environment or system properties, depending upon the value of valueType.

Empty

valueType

Enum [String, Env, "System Properties", Header]

Value Type String:: Treat as a literal value. Env:: Treat as a key into the environment Env[headerValue], and set the returned value. System Properties:: Treat as a key into the JVM’s System Properties, and set the returned value. Header:: Treat as key into the http request headers, and set the returned value.

None

applyTo

Enum [Request, Response, Both]

Where to apply rule Request:: Request only. Response:: Response only. Both:: Both request and response.

None

overwrite

Boolean

Overwrite Overwrite any existing header with same name.

false

stripHeaders

Table 2. Strip headers
Option Type Description Default

stripType

Enum[Key, Value]

Strip when Key:: pattern matches key. Value:: pattern matches value.

None

with

Enum[String, Regex]

With matcher type String:: Case-insensitive string equality. Regex:: Case-insensitive regular expression.

Empty

pattern

String

Using pattern String to match or compile into a regex, depending on the value of with.

Empty

Sample Configuration

{
  "addHeaders": [
    {
      "headerName": "X-APIMAN-IS",
      "headerValue": "free-and-open-source",
      "valueType": "String",
      "applyTo": "Response",
      "overwrite": false
    },
    {
      "headerName": "X-LANG-FROM-ENV",
      "headerValue": "LANG",
      "valueType": "Env",
      "applyTo": "Both",
      "overwrite": true
    },
    {
      "headerName": "X-JAVA-VERSION-FROM-PROPS",
      "headerValue": "java.version",
      "valueType": "System Properties",
      "applyTo": "Request",
      "overwrite": false
    },
    {
      "headerName": "X-NEW-HTTP-HEADER",
      "headerValue": "X-OLD-HTTP-HEADER",
      "valueType": "Header",
      "applyTo": "Request",
      "overwrite": false
    }
  ],
  "stripHeaders": [
    {
      "stripType": "Key",
      "with": "String",
      "pattern": "Authorization"
    },
    {
      "stripType": "Key",
      "with": "Regex",
      "pattern": "^password=.*$"
    }
  ]
}