Headers

Another enhancement provided by TAG Routing is the ability to Add, Set or Remove Headers from the request, via the [HE] flag.

Consider:

RewriteRule ^/tribestream$ https://tribestream.io [P,HE]

And that a Header definition is associated with the Route in the Headers section. In the Routes screen, use the option Add Headers. It will expand a Headers section where Headers can be managed. A few settings are required to manage Headers:

  • An Action (ADD, SET or REMOVE)

  • A Name (the Header name)

  • A Provider (the Header Provider to use)

  • A Value (the Value to calculate the Header)

Add a simple Header with Action ADD, Name TAG, Provider DEFAULT, and Value is awesome.

This rule matches all the incoming requests to TAG to the URL http://localhost:8080/tribestream and proxy to the substitute address https://tribestream.io due to the [P] flag. However, since we also have the [HE] flag, the TAG will add a Header with name TAG and value is awesome. This header will be available in the current request and could be used in subsequent RewriteCond directives or with the Server Variable %{HTTP:TAG}.

Consider:

RewriteRule ^(.*)$ $1 [HE] (1)
RewriteCond %{HTTP:environment} ^qly$ (2)
RewriteRule ^/my-api$ http://qly.my-api.biz/v1 [P] (3)

And a Header with Action ADD, Name environment, Provider DEFAULT and Value qly, in the Route screen Headers section.

1 Match any address and apply Headers configuration. The Header environment with value qly is added to the request.
2 Check for a qly value in the header environment.
3 If the header environment contains the value qly and the request address pattern matches my-api, then the request is proxied to http://qly.my-api.biz/v1.

Please, check the following tables for the supported options to set up Headers Actions and Headers Providers:

Table 3. Headers Actions
Action Description

ADD

Adds a Header to the request. No action if the Header already exists.

SET

Sets a Header to the request. If the Header already exists in the request, it will be overridden.

REMOVE

Removes a Header from the request. If the Header does not exist, no action is performed.

Table 4. Headers Providers
Provider Description

DEFAULT

Simple name and value Provider.

DATE

Sets up the current Date in the Headers.

DIGEST

Calculates a Digest of the provided value.

ENV

Sets up a Header with the provided Environment Variable.

OGNL

Sets up a Header with the provided Java Object property.

JWT

Sets up a Header with the provided JWT property.

API Connections

API Connections can also modify the request Headers in a more generic way. If you use an API Connection in the rule set, and also define Route Headers, the configuration may clash. If that is the case, then the Route Headers definition will have priority over the API Connection Headers definition.