Interface CallbackRequestResult

Can be returned from callbacks to override parts of a request.

All fields are optional, and omitted values will default to the original request value.

interface CallbackRequestResult {
    body?: string | Uint8Array | Buffer;
    headers?: Headers;
    json?: any;
    method?: string;
    rawBody?: Uint8Array | Buffer;
    response?: CallbackResponseResult;
    url?: string;
}

Properties

body?: string | Uint8Array | Buffer

A string or buffer, which replaces the request body if set. This will be automatically content-encoded to match the Content-Encoding defined in your request headers.

If this is set, the Content-Length header will be automatically updated accordingly to match, unless you also provide a headers value that includes a Content-Length header, in which case that will take used as-is.

You should only return one body field: either body, rawBody or json.

headers?: Headers

The replacement HTTP headers, as an object of string keys and either single string or array of string values.

json?: any

A JSON value, which will be stringified and send as a JSON-encoded request body. This will be automatically content-encoded to match the Content-Encoding defined in your request headers.

If this is set, the Content-Length header will be automatically updated accordingly to match, unless you also provide a headers value that includes a Content-Length header, in which case that will take used as-is.

You should only return one body field: either body, rawBody or json.

method?: string

A replacement HTTP method, capitalized.

rawBody?: Uint8Array | Buffer

A buffer, which replaces the request body if set, which is sent exactly as is, and is not automatically encoded.

If this is set, the Content-Length header will be automatically updated accordingly to match, unless you also provide a headers value that includes a Content-Length header, in which case that will take used as-is.

You should only return one body field: either body, rawBody or json.

A response: either a response object defining the fields of a response or the string 'close' to immediately close the connection.

See CallbackResponseMessageResult for the possible fields that can be set to define the response.

If set, the request will not be forwarded at all, and this will be used as the response to immediately return to the client (or for 'close', this will immediately close the connection to the client).

url?: string

The full URL to send the request to. If set, this will redirect the request and automatically update the Host header accordingly, unless you also provide a headers value that includes a Host header, in which case that will take used as-is.