Interface CallbackResponseMessageResult

Can be returned from callbacks to define parts of a response, or override parts when given an existing repsonse.

All fields are optional, and omitted values will default to the original response value or a default value.

interface CallbackResponseMessageResult {
    body?: string | Uint8Array | Buffer;
    headers?: Headers;
    json?: any;
    rawBody?: Uint8Array | Buffer;
    status?: number;
    statusCode?: number;
    statusMessage?: string;
    trailers?: Trailers;
}

Properties

body?: string | Uint8Array | Buffer

A string or buffer, which replaces the response body if set. This will be automatically encoded to match the Content-Encoding defined in your response 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.

Defaults to empty.

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.

Defaults to a minimum set of standard required headers if not set.

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 response 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.

rawBody?: Uint8Array | Buffer

A buffer, which replaces the response 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.

status?: number

Supported only for backward compatibility.

Use statusCode instead.

statusCode?: number

The response status code as a number.

Defaults to 200 if not set.

statusMessage?: string

The response status message, as a string. This is ignored for HTTP/2 responses.

Defaults to the default status message for the status code if not set.

trailers?: Trailers

The replacement HTTP trailers, as an object of string keys and either single string or array of string values. Note that there are not all header fields are valid as trailers, and there are other requirements such as chunked encoding that must be met for trailers to be sent successfully.