Custom Response HTTP Headers

MockMotor allows you to add custom HTTP headers to the response.

The headers' values are scriptable and can use the same variables as the payload field plus response (aka output) variable.

Adding a New Custom Header

To add a new custom header to a response, click on the plus sign in the custom headers section.

Provide a header name.

Removing a Custom Header

To remove a custom header from a response, click on the minus next to the custom header. Confirm the operation.

Fixed Values

For returning a fixed value, place it into the value field.

Computed Values

Each value is computed when it can be interpreted as a valid JS or XQ script.

Programmatically Skip the Header

If you need to skip a particular computed header in a specific situation, make its script result null (for JS) or empty sequence () (for XQ). MockMotor removes the headers that have null values.

For instance, the below scripts provide a fake value to a debug header when the request has a debugInfo parameter. Otherwise, the scripts set the value to null and (), respectively, skipping the header.

JavaScript XQuery
input.debugInfo? “1,2,DB100”:null if( $input//*:debugInfo ) then ( “1,2,DB100” ) else ()

Empty Values

An empty header value is a valid case according to HTTP specs.

For example, in the following response the X-Parts-Taken-From-Cache header has an empty value (probably meaning that the service retrieved all parts from actual storage or backends):

HTTP/1.1 200 OK
Date: Mon, 11 Mar 2019 02:05:32 GMT
Content-Type: application/json;charset=utf-8
X-Parts-Taken-From-Cache:

{ ...

Fixed Empty Values

To provide a fixed empty value, leave the value blank:

Scripted Empty Values

To generate an empty header value, the script should result in an empty string value "" or ''.

Here the script provides an empty string "" as a JS value when the input contains CacheOption: "Never" value. MockMotor then generates an empty value for the X-Parts-Taken-From-Cache header.

Quoted Values

Fixed Quoted Values

If you need to enforce a quoted empty value, use single-quote quotation:

The value here is two double quotes enclosed in two single quotes: '""', i.e. '-"-"-'.

The resulting header is like below:

HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
X-CustomHeader-1: ""

{ ...

Scripted Quoted Values

The same two double quotes enclosed in two single quotes - '"VALUE"', i.e. '-"VALUE"-' - can be used in a script when it needs to generate a quoted value programmatically:

The resulting header is like below:

HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Identity: "N/A"

{ ...