ResponseHandle
The response calls.
The response calls. Every method is a no-op outside a request; invalid arguments throw everywhere.
Import#
ts
import type { ResponseHandle } from "@shadow-js/dusk";
Signature#
ts
interface ResponseHandle {
/** True while a request is answered on the server. False on the client and outside a request. */
readonly inRequest: boolean;
/**
* Sets the status of the page (200 to 599). A status set by a failing loader or an error boundary takes
* precedence over the value set here when it is not 200.
* @throws RangeError for a value that is not an integer from 200 to 599.
*/
setStatus(status: number): void;
/**
* Sets a response header, replacing any value it had. Refused: `set-cookie` (use `setCookie`), `location`
* (use `redirect()`), `content-length` and `transfer-encoding` (the framework owns them).
* @throws TypeError for an invalid name or value, or a refused name.
*/
setHeader(name: string, value: string): void;
/** Adds a response header value after the ones it has. The same refusals as {@link ResponseHandle.setHeader}. */
appendHeader(name: string, value: string): void;
/** Sets a cookie on the response. `options` are the cookie attributes (`path`, `maxAge`, `httpOnly`, ...). */
setCookie(name: string, value: string, options?: CookieOptions): void;
/** Expires a cookie on the response. */
deleteCookie(name: string, options?: CookieOptions): void;
}
Members#
| Name | Type | Description |
|---|---|---|
inRequest |
readonly inRequest: boolean |
True while a request is answered on the server. False on the client and outside a request. |
setStatus |
setStatus(status: number): void |
Sets the status of the page (200 to 599). A status set by a failing loader or an error boundary takes precedence over the value set here when it is not 200. |
setHeader |
setHeader(name: string, value: string): void |
Sets a response header, replacing any value it had. Refused: set-cookie (use setCookie), location (use redirect()), content-length and transfer-encoding (the framework owns them). |
appendHeader |
appendHeader(name: string, value: string): void |
Adds a response header value after the ones it has. The same refusals as ResponseHandle.setHeader. |
setCookie |
setCookie(name: string, value: string, options?: CookieOptions): void |
Sets a cookie on the response. options are the cookie attributes (path, maxAge, httpOnly, ...). |
deleteCookie |
deleteCookie(name: string, options?: CookieOptions): void |
Expires a cookie on the response. |