proxy-request Action #

The proxy-request action forwards the incoming request almost unmodified to an upstream system.

The HTTP method and the request body are taken as-is from the client request. Cookie, Authorization and any hop-by-hop header fields like Connection will be dropped automatically, the remaining header fields will be sent upstream.

The response body is written into fit://request/content/main where it can be directly accessed with the body or the content function. Additional information about the response, such as headers and status code can be found in the $upstream variable.

Usage #

Just like an ordinary request the proxy-request can be configured using a JSON template with the following properties:

origin #

Sets the origin of the upstream system. Either origin or url is required. Type: string.

stripEndpoint #

To be used in connection with origin. If true, strips the endpoint path from the client request URL path before it is added to the upstream origin. Type: boolean, default: false

E.g.

basePath: /api
paths:
  /foo/bar:
  /wildcard/**

For the client request URL https://client.example.com/api/foo/bar, the path is stripped to /.

For the client request URL https://client.example.com/api/wildcard/path/to, the path is stripped to /path/to.

addPrefix #

Inserts a path prefix before the given (client request URL) path, after possible endpoint stripping (see stripEndpoint). Type: string.

url #

Sets the URL to the upstream system. Either url or origin is required.

query #

Overrides the query part of the URL. See the request action for the query syntax.

headers #

Sets or removes request header fields. The syntax is the same as in the request action. To remove a header, set its value to "".

options #

Sets request options. See the request action options for valid options.

Note: that, with proxy-request, in contrast to request, the defaults for exit-on-error, validate-request and validate-response are true, if a definition is configured.

Examples #

Using origin:

<flow>
  <proxy-request>
  {
    "origin": "https://example.com",
    "stripEndpoint": true,
    "addPrefix": "/path/to/api",

    "headers": {
      "X-API-Key": "foo42bar"
    },

    "options": {
      "definition": "upstream.yaml",
      "validate-response": "report-only"
    }
  }
  </proxy-request>
</flow>

With the client request URL http://client.example.com/my/api/foo/bar matching the swagger definition path

basePath: /my/api
paths:
  /foo/**:
    x-flat-flow: proxy.xml

the upstream request URL will be https://example.com/path/to/api/bar.

Using url:

<flow>
  <proxy-request>
  {
    "url": "https://example.com/api/",

    "headers": {
      "X-API-Key": "foo42bar"
    },

    "options": {
      "definition": "upstream.yaml",
      "validate-response": "report-only"
    }
  }
  </proxy-request>
</flow>

See also #