Core
withXSRF
Enables XSRF cookie-to-header token forwarding for HTTP requests.
@defjs/core · Function
Signature
function withXSRF( options?: HttpClientOptions["xsrf"], ): ClientOption;
SSE and WebSocket requests do not get the header. cookieName defaults to XSRF-TOKEN and headerName to X-XSRF-TOKEN when names are omitted.
- The header is set only when all of these hold: the method is not
GET,HEAD,OPTIONS, orTRACE; the request does not already have that header; the client has an endpoint; and, wheneverlocationexists (Window or Worker), the resolved request URL has the same origin aslocation.origin. A cross-origin request does not call the provider. - Without
tokenProvider, the token is read fromdocument.cookieand URL-decoded only whendocumentexists. Workers and servers need a provider to supply a token. - With
tokenProvider, the cookie is never read. The provider receives the request, and its result is the token. An empty string,null, orundefinedmeans no header.
Parameters
Prop
Type
options? HttpClientOptions["xsrf"]Cookie/header names and optional token provider.
Returns
An option that sets config.xsrf.