Interface RequestTransform

This defines the request transforms that we support for all passed through requests (both HTTP and WebSockets).

interface RequestTransform {
    matchReplaceBody?: MatchReplacePairs;
    matchReplaceHost?: {
        replacements: MatchReplacePairs;
        updateHostHeader?: string | boolean;
    };
    matchReplacePath?: MatchReplacePairs;
    matchReplaceQuery?: MatchReplacePairs;
    patchJsonBody?: Operation[];
    replaceBody?: string | Uint8Array | Buffer;
    replaceBodyFromFile?: string;
    replaceHeaders?: Headers;
    replaceHost?: {
        targetHost: string;
        updateHostHeader?: string | boolean;
    };
    replaceMethod?: string;
    setProtocol?: "http" | "https";
    updateHeaders?: Headers;
    updateJsonBody?: {
        [key: string]: any;
    };
}

Hierarchy (view full)

Properties

matchReplaceBody?: MatchReplacePairs

Perform a series of string match & replace operations on the request body.

matchReplaceHost?: {
    replacements: MatchReplacePairs;
    updateHostHeader?: string | boolean;
}

Perform a series of string match & replace operations on the request host.

This cannot be combined with replaceHost.

If updateHostHeader is true, the Host (or :authority for HTTP/2+) header will be updated automatically to match. If updateHostHeader is a string, that will be used directly as the header value. If it's false no change will be made. If not specified this defaults to true.

matchReplacePath?: MatchReplacePairs

Perform a series of string match & replace operations on the request path.

matchReplaceQuery?: MatchReplacePairs

Perform a series of string match & replace operations on the request query string.

patchJsonBody?: Operation[]

A series of operations to apply to the request body in JSON Patch format (RFC 6902).

Any requests which are received with an invalid JSON body that match this rule will fail.

replaceBody?: string | Uint8Array | Buffer

A string or buffer that replaces the request body entirely.

If this is specified, the upstream request will not wait for the original request body, so this may make responses faster than they would be otherwise given large request bodies or slow/streaming clients.

replaceBodyFromFile?: string

The path to a file, which will be used to replace the request body entirely. The file will be re-read for each request, so the body will always reflect the latest file contents.

If this is specified, the upstream request will not wait for the original request body, so this may make responses faster than they would be otherwise given large request bodies or slow/streaming clients.

replaceHeaders?: Headers

A headers object which will completely replace the real request headers.

replaceHost?: {
    targetHost: string;
    updateHostHeader?: string | boolean;
}

Replace the request host with a single fixed value, effectively forwarding all requests to a different hostname.

This cannot be combined with matchReplaceHost.

If updateHostHeader is true, the Host (or :authority for HTTP/2+) header will be updated automatically to match. If updateHostHeader is a string, that will be used directly as the header value. If it's false no change will be made. If not specified this defaults to true.

replaceMethod?: string

A replacement HTTP method. Case insensitive.

setProtocol?: "http" | "https"

Override the request protocol. If replaceHost & matchReplaceHost are not specified and the URL no explicitly specified port, this will automatically switch to the appropriate port (e.g. from 80 to 443).

updateHeaders?: Headers

A headers object which will be merged with the real request headers to add or replace values. Headers with undefined values will be removed.

updateJsonBody?: {
    [key: string]: any;
}

A JSON object which will be merged with the real request body. Undefined values will be removed, and other values will be merged directly with the target value recursively.

Any requests which are received with an invalid JSON body that match this rule will fail.