JavaScript duplex filter - HTTP

A JavaScript duplex filter is potentially invoked for both requests and responses, and is used when you need to do something in both, but would rather keep the filter code in one place instead of having two filters.

This filter will be invoked for any request that satisfies the parameter settings.

This filter will also be invoked for any response that satisfies the parameter settings, provided that the corresponding request also satisfies the parameter settings.

The same context object is shared for both invocations, therefore you can define variables like context.foo during a request and retrieve these variables during a response.

HTTP is a connectionless protocol, therefore there is no context.connectionContext object like with other connectors.

Parameters

URL pattern

Optional. Specifies for which URL(s) the filter should be executed. This does not include the protocol, host and port number. If specified, it can be either:

  • a URL as a string for which this filter should get executed. For instance: /rest/state

  • a regular expression (starting with regex: ) that matches the URL. For instance: regex:/rest/state/[0-9]+


Method

Optional. If specified, the HTTP method (e.g. GET, POST, PUT, etc...) for which this filter should get executed. If not specified, all methods will match.


Client IPs

Optional. If specified, a comma-separated (or line break separated) list of IP4 or IP6 addresses or regular expressions for IP addresses. If specified, only requests from matching IP addresses will cause the execution of the filter. For example:

  • 201.43.1.33, 88.49.9.199, regex:88\.48\.23\.\d{1,3}

  • 0:0:0:0:0:0:0:1, regex:2600:1700:6270:6aa0:51:92ca:\d+:\d+


Request header patterns

Optional. If specified, a newline-separated list of header specifications which must match the request's headers. The name of the header is a simple string, followed by a colon, and a regular expression for the header value. For instance:

Content-type: ((application/json)|(text/json))

If more than one pattern is specified (separated by line breaks), then the filter will be executed if at least one of the patterns matches at least one of the headers.


Response header patterns

Exactly like Request header patterns, but for responses.


Request content pattern

A regular expression that must match the body of the request. This is only valid for request methods that can contain a body (normally POST, PUT, and PATCH), and in which the body is text. If the request's body is not text, this parameter should not be set.

For example, if the body of a request contains the following:

<person>

<name>Jane Hernandez</name>

</person>

then either of the following regular expressions would match:

.*\<name\>.*nandez.*\</name\>.*

.*Jane Her[a-z]+.*


Response content pattern

Exactly like Request content pattern, but for responses.

Context

This filter does not define any variables besides the usual ones.