@wooksjs/event-http 0.6.6 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -45
- package/dist/index.cjs +1148 -968
- package/dist/index.d.ts +364 -308
- package/dist/index.mjs +1104 -920
- package/package.json +7 -7
- package/skills/wooksjs-event-http/SKILL.md +28 -21
- package/skills/wooksjs-event-http/core.md +83 -228
- package/skills/wooksjs-event-http/request.md +131 -147
- package/skills/wooksjs-event-http/response.md +166 -235
- package/skills/wooksjs-event-http/testing.md +150 -0
- package/skills/wooksjs-event-http/addons.md +0 -307
- package/skills/wooksjs-event-http/error-handling.md +0 -253
- package/skills/wooksjs-event-http/event-core.md +0 -562
- package/skills/wooksjs-event-http/routing.md +0 -412
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,110 @@
|
|
|
1
1
|
import * as _wooksjs_event_core from '@wooksjs/event-core';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { EventContext, Logger, EventContextOptions } from '@wooksjs/event-core';
|
|
3
|
+
export { EventContext, EventContextOptions, useLogger, useRouteParams } from '@wooksjs/event-core';
|
|
4
4
|
import * as http from 'http';
|
|
5
|
-
import { IncomingMessage, ServerResponse,
|
|
6
|
-
import { URLSearchParams } from 'url';
|
|
5
|
+
import { IncomingHttpHeaders, IncomingMessage, ServerResponse, Server } from 'http';
|
|
7
6
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
8
|
-
import {
|
|
7
|
+
import { URLSearchParams } from 'url';
|
|
9
8
|
import * as wooks from 'wooks';
|
|
10
|
-
import { TWooksHandler, TWooksOptions, WooksAdapterBase, Wooks } from 'wooks';
|
|
9
|
+
import { TWooksHandler, TWooksOptions, WooksAdapterBase, Wooks, WooksUpgradeHandler } from 'wooks';
|
|
10
|
+
import { TConsoleBase } from '@prostojs/logger';
|
|
11
11
|
import { ListenOptions } from 'net';
|
|
12
|
+
import { Duplex } from 'stream';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Provides access to parsed request cookies.
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const { getCookie, raw } = useCookies()
|
|
19
|
+
* const sessionId = getCookie('session_id')
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const useCookies: (ctx?: EventContext) => {
|
|
23
|
+
raw: string | undefined;
|
|
24
|
+
getCookie: (name: string) => string | null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Short names for common Accept MIME types. */
|
|
28
|
+
type KnownAcceptType = 'json' | 'html' | 'xml' | 'text';
|
|
29
|
+
/** Provides helpers to check the request's Accept header for supported MIME types. */
|
|
30
|
+
declare const useAccept: (ctx?: EventContext) => {
|
|
31
|
+
accept: string | undefined;
|
|
32
|
+
has: (type: KnownAcceptType | (string & {})) => boolean;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** Short names for common Authorization schemes. */
|
|
36
|
+
type KnownAuthType = 'basic' | 'bearer';
|
|
37
|
+
/**
|
|
38
|
+
* Provides parsed access to the Authorization header (type, credentials, Basic decoding).
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const { is, credentials, basicCredentials } = useAuthorization()
|
|
42
|
+
* if (is('bearer')) { const token = credentials() }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare const useAuthorization: (ctx?: EventContext) => {
|
|
46
|
+
authorization: string | undefined;
|
|
47
|
+
type: () => string | null;
|
|
48
|
+
credentials: () => string | null;
|
|
49
|
+
is: (type: KnownAuthType | (string & {})) => boolean;
|
|
50
|
+
basicCredentials: () => {
|
|
51
|
+
username: string;
|
|
52
|
+
password: string;
|
|
53
|
+
} | null;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the incoming request headers.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { host, authorization } = useHeaders()
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function useHeaders(ctx?: EventContext): IncomingHttpHeaders;
|
|
12
64
|
|
|
65
|
+
/** Default safety limits for request body reading (size, ratio, timeout). */
|
|
66
|
+
declare const DEFAULT_LIMITS: {
|
|
67
|
+
readonly maxCompressed: number;
|
|
68
|
+
readonly maxInflated: number;
|
|
69
|
+
readonly maxRatio: 100;
|
|
70
|
+
readonly readTimeoutMs: 10000;
|
|
71
|
+
};
|
|
72
|
+
/** @internal Exported for test pre-seeding via `ctx.set(rawBodySlot, ...)`. */
|
|
73
|
+
declare const rawBodySlot: _wooksjs_event_core.Cached<Promise<Buffer$1<ArrayBufferLike>>>;
|
|
74
|
+
/**
|
|
75
|
+
* Provides access to the incoming HTTP request (method, url, headers, body, IP).
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* const { method, url, raw, rawBody, getIp } = useRequest()
|
|
79
|
+
* const body = await rawBody()
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare const useRequest: (ctx?: EventContext) => {
|
|
83
|
+
raw: http.IncomingMessage;
|
|
84
|
+
url: string | undefined;
|
|
85
|
+
method: string | undefined;
|
|
86
|
+
headers: http.IncomingHttpHeaders;
|
|
87
|
+
rawBody: () => Promise<Buffer$1<ArrayBufferLike>>;
|
|
88
|
+
reqId: () => string;
|
|
89
|
+
getIp: (options?: {
|
|
90
|
+
trustProxy: boolean;
|
|
91
|
+
}) => string;
|
|
92
|
+
getIpList: () => {
|
|
93
|
+
remoteIp: string;
|
|
94
|
+
forwarded: string[];
|
|
95
|
+
};
|
|
96
|
+
isCompressed: () => boolean;
|
|
97
|
+
getMaxCompressed: () => number;
|
|
98
|
+
setMaxCompressed: (limit: number) => void;
|
|
99
|
+
getReadTimeoutMs: () => number;
|
|
100
|
+
setReadTimeoutMs: (limit: number) => void;
|
|
101
|
+
getMaxInflated: () => number;
|
|
102
|
+
setMaxInflated: (limit: number) => void;
|
|
103
|
+
getMaxRatio: () => number;
|
|
104
|
+
setMaxRatio: (limit: number) => void;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** Maps numeric HTTP status codes to their human-readable descriptions. */
|
|
13
108
|
declare const httpStatusCodes: {
|
|
14
109
|
100: string;
|
|
15
110
|
101: string;
|
|
@@ -75,6 +170,7 @@ declare const httpStatusCodes: {
|
|
|
75
170
|
510: string;
|
|
76
171
|
511: string;
|
|
77
172
|
};
|
|
173
|
+
/** Enum of all standard HTTP status codes (100–511). */
|
|
78
174
|
declare enum EHttpStatusCode {
|
|
79
175
|
Continue = 100,
|
|
80
176
|
SwitchingProtocols = 101,
|
|
@@ -140,63 +236,66 @@ declare enum EHttpStatusCode {
|
|
|
140
236
|
NotExtended = 510,
|
|
141
237
|
NetworkAuthenticationRequired = 511
|
|
142
238
|
}
|
|
239
|
+
/** Union of HTTP 4xx client error status codes. */
|
|
143
240
|
type THttpBadRequestCodes = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
241
|
+
/** Union of HTTP 5xx server error status codes. */
|
|
144
242
|
type THttpServerErrorCodes = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
243
|
+
/** Union of all HTTP error status codes (4xx + 5xx). */
|
|
145
244
|
type THttpErrorCodes = THttpBadRequestCodes | THttpServerErrorCodes;
|
|
146
245
|
|
|
246
|
+
/** Represents an HTTP error with a status code and optional structured body. */
|
|
247
|
+
declare class HttpError<T extends TWooksErrorBody = TWooksErrorBody> extends Error {
|
|
248
|
+
protected code: THttpErrorCodes;
|
|
249
|
+
protected _body: string | T;
|
|
250
|
+
name: string;
|
|
251
|
+
constructor(code?: THttpErrorCodes, _body?: string | T);
|
|
252
|
+
get body(): TWooksErrorBodyExt;
|
|
253
|
+
}
|
|
254
|
+
/** Base shape for an HTTP error response body. */
|
|
255
|
+
interface TWooksErrorBody {
|
|
256
|
+
message: string;
|
|
257
|
+
statusCode: EHttpStatusCode;
|
|
258
|
+
error?: string;
|
|
259
|
+
}
|
|
260
|
+
/** Extended error body that always includes the error description string. */
|
|
261
|
+
interface TWooksErrorBodyExt extends TWooksErrorBody {
|
|
262
|
+
error: string;
|
|
263
|
+
}
|
|
264
|
+
|
|
147
265
|
type TTimeUnit = 'ms' | 's' | 'm' | 'h' | 'd' | 'w' | 'M' | 'Y';
|
|
148
266
|
type TTimeSingleString = `${number}${TTimeUnit}`;
|
|
149
267
|
type TTimeMultiString = `${TTimeSingleString}${TTimeSingleString | ''}${TTimeSingleString | ''}${TTimeSingleString | ''}`;
|
|
150
268
|
|
|
151
|
-
|
|
152
|
-
toJson<T = unknown>(): T;
|
|
153
|
-
}
|
|
154
|
-
|
|
269
|
+
/** Raw HTTP event data attached to the event context. */
|
|
155
270
|
interface THttpEventData {
|
|
156
271
|
req: IncomingMessage;
|
|
157
272
|
res: ServerResponse;
|
|
158
273
|
requestLimits?: TRequestLimits;
|
|
159
274
|
}
|
|
160
|
-
|
|
161
|
-
type: 'HTTP';
|
|
162
|
-
}
|
|
163
|
-
interface THttpContextStore {
|
|
164
|
-
searchParams?: TSearchParamsCache;
|
|
165
|
-
cookies?: Record<string, string | null>;
|
|
166
|
-
setCookies?: Record<string, TSetCookieData>;
|
|
167
|
-
accept?: Record<string, boolean>;
|
|
168
|
-
authorization?: TAuthCache;
|
|
169
|
-
setHeader?: Record<string, string | string[]>;
|
|
170
|
-
request?: TRequestCache;
|
|
171
|
-
response?: {
|
|
172
|
-
responded: boolean;
|
|
173
|
-
};
|
|
174
|
-
status?: {
|
|
175
|
-
code: EHttpStatusCode;
|
|
176
|
-
};
|
|
177
|
-
}
|
|
275
|
+
/** Data for a pending outgoing `Set-Cookie` header (name is stored as the key in `HttpResponse._cookies`). */
|
|
178
276
|
interface TSetCookieData {
|
|
179
277
|
value: string;
|
|
180
278
|
attrs: TCookieAttributesInput;
|
|
181
279
|
}
|
|
280
|
+
/** Partial cookie attributes — all fields are optional. */
|
|
182
281
|
type TCookieAttributesInput = Partial<TCookieAttributes>;
|
|
282
|
+
/** Full set of attributes for a `Set-Cookie` header (RFC 6265 §4.1). */
|
|
183
283
|
interface TCookieAttributes {
|
|
284
|
+
/** Cookie expiration date. */
|
|
184
285
|
expires: Date | string | number;
|
|
286
|
+
/** Max age in seconds, or a time string (e.g. `'1h'`). */
|
|
185
287
|
maxAge: number | TTimeMultiString;
|
|
288
|
+
/** Cookie domain. */
|
|
186
289
|
domain: string;
|
|
290
|
+
/** Cookie path. */
|
|
187
291
|
path: string;
|
|
292
|
+
/** Secure flag — cookie only sent over HTTPS. */
|
|
188
293
|
secure: boolean;
|
|
294
|
+
/** HttpOnly flag — cookie not accessible via JavaScript. */
|
|
189
295
|
httpOnly: boolean;
|
|
296
|
+
/** SameSite policy. */
|
|
190
297
|
sameSite: boolean | 'Lax' | 'None' | 'Strict';
|
|
191
298
|
}
|
|
192
|
-
interface TAuthCache {
|
|
193
|
-
type: string | null;
|
|
194
|
-
credentials: string | null;
|
|
195
|
-
basicCredentials: {
|
|
196
|
-
username: string;
|
|
197
|
-
password: string;
|
|
198
|
-
} | null;
|
|
199
|
-
}
|
|
200
299
|
/** App-level request body limits (all optional, defaults apply when omitted). */
|
|
201
300
|
interface TRequestLimits {
|
|
202
301
|
/** Max compressed body size in bytes (default: 1 MB). */
|
|
@@ -210,81 +309,8 @@ interface TRequestLimits {
|
|
|
210
309
|
/** Internal flag: true when this object is a per-request clone (copy-on-write). */
|
|
211
310
|
perRequest?: boolean;
|
|
212
311
|
}
|
|
213
|
-
interface TRequestCache {
|
|
214
|
-
rawBody: Promise<Buffer>;
|
|
215
|
-
parsed: unknown;
|
|
216
|
-
forwardedIp?: string;
|
|
217
|
-
remoteIp?: string;
|
|
218
|
-
ipList?: {
|
|
219
|
-
remoteIp: string;
|
|
220
|
-
forwarded: string[];
|
|
221
|
-
};
|
|
222
|
-
contentEncodings?: string[];
|
|
223
|
-
isCompressed?: boolean;
|
|
224
|
-
}
|
|
225
|
-
interface TSearchParamsCache {
|
|
226
|
-
raw?: string;
|
|
227
|
-
urlSearchParams?: WooksURLSearchParams;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Provides access to parsed request cookies.
|
|
232
|
-
* @example
|
|
233
|
-
* ```ts
|
|
234
|
-
* const { getCookie, rawCookies } = useCookies()
|
|
235
|
-
* const sessionId = getCookie('session_id')
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
|
-
declare function useCookies(): {
|
|
239
|
-
rawCookies: string | undefined;
|
|
240
|
-
getCookie: (name: string) => string | null;
|
|
241
|
-
};
|
|
242
|
-
/** Provides methods to set, get, remove, and clear outgoing response cookies. */
|
|
243
|
-
declare function useSetCookies(): {
|
|
244
|
-
setCookie: (name: string, value: string, attrs?: Partial<TCookieAttributes>) => void;
|
|
245
|
-
getCookie: <K2 extends string>(key2: K2) => TSetCookieData | undefined;
|
|
246
|
-
removeCookie: <K2 extends string>(key2: K2) => void;
|
|
247
|
-
clearCookies: () => void;
|
|
248
|
-
cookies: () => string[];
|
|
249
|
-
};
|
|
250
|
-
/** Returns a hookable accessor for a single outgoing cookie by name. */
|
|
251
|
-
declare function useSetCookie(name: string): {
|
|
252
|
-
name: string;
|
|
253
|
-
type: string;
|
|
254
|
-
} & _wooksjs_event_core.THook<string, "value"> & _wooksjs_event_core.THook<TCookieAttributes, "attrs">;
|
|
255
|
-
/** Hook type returned by {@link useSetCookie}. */
|
|
256
|
-
type TCookieHook = ReturnType<typeof useSetCookie>;
|
|
257
|
-
|
|
258
|
-
/** Provides helpers to check the request's Accept header for supported MIME types. */
|
|
259
|
-
declare function useAccept(): {
|
|
260
|
-
accept: string | undefined;
|
|
261
|
-
accepts: (mime: string) => unknown;
|
|
262
|
-
acceptsJson: () => unknown;
|
|
263
|
-
acceptsXml: () => unknown;
|
|
264
|
-
acceptsText: () => unknown;
|
|
265
|
-
acceptsHtml: () => unknown;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Provides parsed access to the Authorization header (type, credentials, Basic decoding).
|
|
270
|
-
* @example
|
|
271
|
-
* ```ts
|
|
272
|
-
* const { isBearer, authRawCredentials, basicCredentials } = useAuthorization()
|
|
273
|
-
* if (isBearer()) { const token = authRawCredentials() }
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
declare function useAuthorization(): {
|
|
277
|
-
authorization: string | undefined;
|
|
278
|
-
authType: () => string | null;
|
|
279
|
-
authRawCredentials: () => string | null;
|
|
280
|
-
isBasic: () => boolean;
|
|
281
|
-
isBearer: () => boolean;
|
|
282
|
-
basicCredentials: () => {
|
|
283
|
-
username: string;
|
|
284
|
-
password: string;
|
|
285
|
-
} | null;
|
|
286
|
-
};
|
|
287
312
|
|
|
313
|
+
/** Cache-Control directive object (RFC 7234 §5.2.2). All fields are optional. */
|
|
288
314
|
interface TCacheControl {
|
|
289
315
|
mustRevalidate?: boolean;
|
|
290
316
|
noCache?: boolean | string;
|
|
@@ -293,245 +319,196 @@ interface TCacheControl {
|
|
|
293
319
|
public?: boolean;
|
|
294
320
|
private?: boolean | string;
|
|
295
321
|
proxyRevalidate?: boolean;
|
|
322
|
+
/** Max age in seconds, or a time string (e.g. `'3h 30m'`). */
|
|
296
323
|
maxAge?: number | TTimeMultiString;
|
|
324
|
+
/** Shared cache max age in seconds, or a time string. */
|
|
297
325
|
sMaxage?: number | TTimeMultiString;
|
|
298
326
|
}
|
|
327
|
+
/** Renders a `TCacheControl` object into a `Cache-Control` header string. */
|
|
299
328
|
declare function renderCacheControl(data: TCacheControl): string;
|
|
300
329
|
|
|
301
|
-
/** Provides helpers to set cache-related response headers (Cache-Control, Expires, Age, Pragma). */
|
|
302
|
-
declare function useSetCacheControl(): {
|
|
303
|
-
setExpires: (value: Date | string | number) => void;
|
|
304
|
-
setAge: (value: number | TTimeMultiString) => void;
|
|
305
|
-
setPragmaNoCache: (value?: boolean) => void;
|
|
306
|
-
setCacheControl: (data: TCacheControl) => void;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Returns the incoming request headers.
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* const { host, authorization } = useHeaders()
|
|
314
|
-
* ```
|
|
315
|
-
*/
|
|
316
|
-
declare function useHeaders(): IncomingHttpHeaders;
|
|
317
330
|
/**
|
|
318
|
-
*
|
|
331
|
+
* Manages response status, headers, cookies, cache control, and body for an HTTP request.
|
|
332
|
+
*
|
|
333
|
+
* All header mutations are accumulated in memory and flushed in a single `writeHead()` call
|
|
334
|
+
* when `send()` is invoked. Setter methods are chainable.
|
|
335
|
+
*
|
|
319
336
|
* @example
|
|
320
337
|
* ```ts
|
|
321
|
-
* const
|
|
322
|
-
* setHeader('x-
|
|
338
|
+
* const response = useResponse()
|
|
339
|
+
* response.setStatus(200).setHeader('x-custom', 'value')
|
|
340
|
+
* response.setCookie('session', 'abc', { httpOnly: true })
|
|
323
341
|
* ```
|
|
324
342
|
*/
|
|
325
|
-
declare
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
343
|
+
declare class HttpResponse {
|
|
344
|
+
protected readonly _res: ServerResponse;
|
|
345
|
+
protected readonly _req: IncomingMessage;
|
|
346
|
+
protected readonly _logger: Logger;
|
|
347
|
+
/**
|
|
348
|
+
* @param _res - The underlying Node.js `ServerResponse`.
|
|
349
|
+
* @param _req - The underlying Node.js `IncomingMessage`.
|
|
350
|
+
* @param _logger - Logger instance for error reporting.
|
|
351
|
+
* @param defaultHeaders - Optional headers to pre-populate on this response (e.g. from `securityHeaders()`).
|
|
352
|
+
*/
|
|
353
|
+
constructor(_res: ServerResponse, _req: IncomingMessage, _logger: Logger, defaultHeaders?: Record<string, string | string[]>);
|
|
354
|
+
protected _status: EHttpStatusCode;
|
|
355
|
+
protected _body: unknown;
|
|
356
|
+
protected _headers: Record<string, string | string[]>;
|
|
357
|
+
protected _cookies: Record<string, TSetCookieData>;
|
|
358
|
+
protected _rawCookies: string[];
|
|
359
|
+
protected _hasCookies: boolean;
|
|
360
|
+
protected _responded: boolean;
|
|
361
|
+
/** The HTTP status code. If not set, it is inferred automatically when `send()` is called. */
|
|
362
|
+
get status(): EHttpStatusCode;
|
|
363
|
+
set status(value: EHttpStatusCode);
|
|
364
|
+
/** Sets the HTTP status code (chainable). */
|
|
365
|
+
setStatus(value: EHttpStatusCode): this;
|
|
366
|
+
/** The response body. Automatically serialized by `send()` (objects → JSON, strings → text). */
|
|
367
|
+
get body(): unknown;
|
|
368
|
+
set body(value: unknown);
|
|
369
|
+
/** Sets the response body (chainable). */
|
|
370
|
+
setBody(value: unknown): this;
|
|
371
|
+
/** Sets a single response header (chainable). Arrays produce multi-value headers. */
|
|
372
|
+
setHeader(name: string, value: string | number | string[]): this;
|
|
373
|
+
/** Batch-sets multiple response headers from a record (chainable). Existing keys are overwritten. */
|
|
374
|
+
setHeaders(headers: Record<string, string | string[]>): this;
|
|
375
|
+
/** Returns the value of a response header, or `undefined` if not set. */
|
|
376
|
+
getHeader(name: string): string | string[] | undefined;
|
|
377
|
+
/** Removes a response header (chainable). */
|
|
378
|
+
removeHeader(name: string): this;
|
|
379
|
+
/** Returns a read-only snapshot of all response headers. */
|
|
380
|
+
headers(): Readonly<Record<string, string | string[]>>;
|
|
381
|
+
/** Sets the `Content-Type` response header (chainable). */
|
|
382
|
+
setContentType(value: string): this;
|
|
383
|
+
/** Returns the current `Content-Type` header value. */
|
|
384
|
+
getContentType(): string | string[] | undefined;
|
|
385
|
+
/** Sets the `Access-Control-Allow-Origin` header (chainable). Defaults to `'*'`. */
|
|
386
|
+
enableCors(origin?: string): this;
|
|
387
|
+
/** Sets an outgoing `Set-Cookie` header with optional attributes (chainable). */
|
|
388
|
+
setCookie(name: string, value: string, attrs?: Partial<TCookieAttributes>): this;
|
|
389
|
+
/** Returns a previously set cookie's data, or `undefined` if not set. */
|
|
390
|
+
getCookie(name: string): TSetCookieData | undefined;
|
|
391
|
+
/** Removes a cookie from the outgoing set list (chainable). */
|
|
392
|
+
removeCookie(name: string): this;
|
|
393
|
+
/** Removes all outgoing cookies (chainable). */
|
|
394
|
+
clearCookies(): this;
|
|
395
|
+
/** Appends a raw `Set-Cookie` header string (chainable). Use when you need full control over the cookie format. */
|
|
396
|
+
setCookieRaw(rawValue: string): this;
|
|
397
|
+
/** Sets the `Cache-Control` header from a directive object (chainable). */
|
|
398
|
+
setCacheControl(data: TCacheControl): this;
|
|
399
|
+
/** Sets the `Age` header in seconds (chainable). Accepts a number or time string (e.g. `'2h 15m'`). */
|
|
400
|
+
setAge(value: number | TTimeMultiString): this;
|
|
401
|
+
/** Sets the `Expires` header (chainable). Accepts a `Date`, date string, or timestamp. */
|
|
402
|
+
setExpires(value: Date | string | number): this;
|
|
403
|
+
/** Sets or clears the `Pragma: no-cache` header (chainable). */
|
|
404
|
+
setPragmaNoCache(value?: boolean): this;
|
|
405
|
+
/**
|
|
406
|
+
* Returns the underlying Node.js `ServerResponse`.
|
|
407
|
+
* @param passthrough - If `true`, the framework still manages the response lifecycle. If `false` (default), the response is marked as "responded" and the framework will not touch it.
|
|
408
|
+
*/
|
|
409
|
+
getRawRes(passthrough?: boolean): ServerResponse;
|
|
410
|
+
/** Whether the response has already been sent (or the underlying stream is no longer writable). */
|
|
411
|
+
get responded(): boolean;
|
|
412
|
+
protected renderBody(): string | Uint8Array;
|
|
413
|
+
protected renderError(data: TWooksErrorBodyExt, _ctx: EventContext): void;
|
|
414
|
+
/** Renders and sends an HTTP error response. Called automatically by the framework when a handler throws an `HttpError`. */
|
|
415
|
+
sendError(error: HttpError, ctx: EventContext): void | Promise<void>;
|
|
416
|
+
/**
|
|
417
|
+
* Finalizes and sends the response.
|
|
418
|
+
*
|
|
419
|
+
* Flushes all accumulated headers (including cookies) in a single `writeHead()` call,
|
|
420
|
+
* then writes the body. Supports `Readable` streams, `fetch` `Response` objects, and regular values.
|
|
421
|
+
*
|
|
422
|
+
* @throws Error if the response was already sent.
|
|
423
|
+
*/
|
|
424
|
+
send(): void | Promise<void>;
|
|
425
|
+
private finalizeCookies;
|
|
426
|
+
private autoStatus;
|
|
427
|
+
private sendStream;
|
|
428
|
+
private sendFetchResponse;
|
|
429
|
+
private sendRegular;
|
|
430
|
+
}
|
|
340
431
|
|
|
341
|
-
/** Default safety limits for request body reading (size, ratio, timeout). */
|
|
342
|
-
declare const DEFAULT_LIMITS: {
|
|
343
|
-
readonly maxCompressed: number;
|
|
344
|
-
readonly maxInflated: number;
|
|
345
|
-
readonly maxRatio: 100;
|
|
346
|
-
readonly readTimeoutMs: 10000;
|
|
347
|
-
};
|
|
348
432
|
/**
|
|
349
|
-
*
|
|
433
|
+
* Returns the HttpResponse instance for the current request.
|
|
434
|
+
* All response operations (status, headers, cookies, cache control, sending)
|
|
435
|
+
* are methods on the returned object.
|
|
436
|
+
*
|
|
350
437
|
* @example
|
|
351
438
|
* ```ts
|
|
352
|
-
* const
|
|
353
|
-
*
|
|
439
|
+
* const response = useResponse()
|
|
440
|
+
* response.status = 200
|
|
441
|
+
* response.setHeader('x-custom', 'value')
|
|
442
|
+
* response.setCookie('session', 'abc', { httpOnly: true })
|
|
354
443
|
* ```
|
|
355
444
|
*/
|
|
356
|
-
declare function
|
|
357
|
-
rawRequest: http.IncomingMessage;
|
|
358
|
-
url: string | undefined;
|
|
359
|
-
method: string | undefined;
|
|
360
|
-
headers: http.IncomingHttpHeaders;
|
|
361
|
-
rawBody: () => Promise<Buffer$1<ArrayBufferLike>>;
|
|
362
|
-
reqId: () => string;
|
|
363
|
-
getIp: (options?: {
|
|
364
|
-
trustProxy: boolean;
|
|
365
|
-
}) => string;
|
|
366
|
-
getIpList: () => {
|
|
367
|
-
remoteIp: string;
|
|
368
|
-
forwarded: string[];
|
|
369
|
-
};
|
|
370
|
-
isCompressed: () => boolean;
|
|
371
|
-
getMaxCompressed: () => number;
|
|
372
|
-
setMaxCompressed: (limit: number) => void;
|
|
373
|
-
getReadTimeoutMs: () => number;
|
|
374
|
-
setReadTimeoutMs: (limit: number) => void;
|
|
375
|
-
getMaxInflated: () => number;
|
|
376
|
-
setMaxInflated: (limit: number) => void;
|
|
377
|
-
getMaxRatio: () => number;
|
|
378
|
-
setMaxRatio: (limit: number) => void;
|
|
379
|
-
};
|
|
445
|
+
declare function useResponse(ctx?: EventContext): HttpResponse;
|
|
380
446
|
|
|
381
|
-
interface TUseResponseOptions {
|
|
382
|
-
passthrough: boolean;
|
|
383
|
-
}
|
|
384
447
|
/**
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* status(200)
|
|
390
|
-
* ```
|
|
448
|
+
* Extended `URLSearchParams` with safe JSON conversion.
|
|
449
|
+
*
|
|
450
|
+
* Rejects prototype-pollution keys (`__proto__`, `constructor`, `prototype`) and duplicate non-array keys.
|
|
451
|
+
* Array parameters are detected by a trailing `[]` in the key name (e.g. `tags[]=a&tags[]=b`).
|
|
391
452
|
*/
|
|
392
|
-
declare
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
};
|
|
397
|
-
/** Returns a hookable accessor for the response status code. */
|
|
398
|
-
declare function useStatus(): {
|
|
399
|
-
value: EHttpStatusCode;
|
|
400
|
-
isDefined: boolean;
|
|
401
|
-
};
|
|
402
|
-
/** Hook type returned by {@link useStatus}. */
|
|
403
|
-
type TStatusHook = ReturnType<typeof useStatus>;
|
|
453
|
+
declare class WooksURLSearchParams extends URLSearchParams {
|
|
454
|
+
/** Converts query parameters to a plain object. Array params (keys ending with `[]`) become `string[]`. */
|
|
455
|
+
toJson<T = unknown>(): T;
|
|
456
|
+
}
|
|
404
457
|
|
|
405
458
|
/**
|
|
406
459
|
* Provides access to URL search (query) parameters from the request.
|
|
407
460
|
* @example
|
|
408
461
|
* ```ts
|
|
409
|
-
* const {
|
|
410
|
-
* const page =
|
|
462
|
+
* const { params, toJson } = useUrlParams()
|
|
463
|
+
* const page = params().get('page')
|
|
411
464
|
* ```
|
|
412
465
|
*/
|
|
413
|
-
declare
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
466
|
+
declare const useUrlParams: (ctx?: EventContext) => {
|
|
467
|
+
raw: () => string;
|
|
468
|
+
params: () => WooksURLSearchParams;
|
|
469
|
+
toJson: () => unknown;
|
|
417
470
|
};
|
|
418
471
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
render: (response: BaseHttpResponse<T>) => string | Uint8Array;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
declare class BaseHttpResponse<BodyType = unknown> {
|
|
427
|
-
protected renderer: BaseHttpResponseRenderer;
|
|
428
|
-
constructor(renderer?: BaseHttpResponseRenderer);
|
|
429
|
-
protected _status: EHttpStatusCode;
|
|
430
|
-
protected _body?: BodyType;
|
|
431
|
-
protected _headers: Record<string, string | string[]>;
|
|
432
|
-
get status(): EHttpStatusCode;
|
|
433
|
-
set status(value: EHttpStatusCode);
|
|
434
|
-
get body(): BodyType | undefined;
|
|
435
|
-
set body(value: BodyType | undefined);
|
|
436
|
-
setStatus(value: EHttpStatusCode): this;
|
|
437
|
-
setBody(value: BodyType): this;
|
|
438
|
-
getContentType(): string | string[];
|
|
439
|
-
setContentType(value: string): this;
|
|
440
|
-
enableCors(origin?: string): this;
|
|
441
|
-
setCookie(name: string, value: string, attrs?: Partial<TCookieAttributes>): this;
|
|
442
|
-
setCacheControl(data: TCacheControl): void;
|
|
443
|
-
setCookieRaw(rawValue: string): this;
|
|
444
|
-
header(name: string, value: string): this;
|
|
445
|
-
setHeader(name: string, value: string): this;
|
|
446
|
-
getHeader(name: string): string | string[];
|
|
447
|
-
protected mergeHeaders(): this;
|
|
448
|
-
protected mergeStatus(renderedBody: string | Uint8Array | boolean): this;
|
|
449
|
-
protected mergeFetchStatus(fetchStatus: number): void;
|
|
450
|
-
protected panic(text: string, logger: TConsoleBase): void;
|
|
451
|
-
respond(): Promise<unknown>;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/** Represents an HTTP error with a status code and optional structured body. */
|
|
455
|
-
declare class HttpError<T extends TWooksErrorBody = TWooksErrorBody> extends Error {
|
|
456
|
-
protected code: THttpErrorCodes;
|
|
457
|
-
protected _body: string | T;
|
|
458
|
-
name: string;
|
|
459
|
-
constructor(code?: THttpErrorCodes, _body?: string | T);
|
|
460
|
-
get body(): TWooksErrorBodyExt;
|
|
461
|
-
protected renderer?: HttpErrorRenderer;
|
|
462
|
-
attachRenderer(renderer: HttpErrorRenderer): void;
|
|
463
|
-
getRenderer(): HttpErrorRenderer | undefined;
|
|
464
|
-
}
|
|
465
|
-
/** Base shape for an HTTP error response body. */
|
|
466
|
-
interface TWooksErrorBody {
|
|
467
|
-
message: string;
|
|
468
|
-
statusCode: EHttpStatusCode;
|
|
469
|
-
error?: string;
|
|
470
|
-
}
|
|
471
|
-
/** Extended error body that always includes the error description string. */
|
|
472
|
-
interface TWooksErrorBodyExt extends TWooksErrorBody {
|
|
473
|
-
error: string;
|
|
474
|
-
}
|
|
472
|
+
/** Creates an async event context for an incoming HTTP request/response pair. */
|
|
473
|
+
declare function createHttpContext(data: THttpEventData, options: EventContextOptions, ResponseClass?: typeof HttpResponse): <R>(fn: () => R) => R;
|
|
474
|
+
/** Returns the current HTTP event context. */
|
|
475
|
+
declare function useHttpContext(ctx?: EventContext): EventContext;
|
|
475
476
|
|
|
476
|
-
/**
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
constructor(opts?: {
|
|
485
|
-
version: string;
|
|
486
|
-
poweredBy: string;
|
|
487
|
-
link: string;
|
|
488
|
-
image: string;
|
|
489
|
-
} | undefined);
|
|
490
|
-
protected icons: {
|
|
491
|
-
401: string;
|
|
492
|
-
403: string;
|
|
493
|
-
404: string;
|
|
494
|
-
500: string;
|
|
495
|
-
};
|
|
477
|
+
/**
|
|
478
|
+
* Default `HttpResponse` subclass used by `createHttpApp`.
|
|
479
|
+
*
|
|
480
|
+
* Overrides error rendering to produce content-negotiated responses (JSON, HTML, or plain text)
|
|
481
|
+
* based on the request's `Accept` header. HTML error pages include SVG icons and framework branding.
|
|
482
|
+
*/
|
|
483
|
+
declare class WooksHttpResponse extends HttpResponse {
|
|
484
|
+
/** Registers framework metadata (name, version, link, logo) used in HTML error pages. */
|
|
496
485
|
static registerFramework(opts: {
|
|
497
486
|
version: string;
|
|
498
487
|
poweredBy: string;
|
|
499
488
|
link: string;
|
|
500
489
|
image: string;
|
|
501
490
|
}): void;
|
|
502
|
-
|
|
503
|
-
renderText(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
|
|
504
|
-
renderJson(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
|
|
505
|
-
render(response: BaseHttpResponse<TWooksErrorBodyExt>): string;
|
|
491
|
+
protected renderError(data: TWooksErrorBodyExt, ctx: EventContext): void;
|
|
506
492
|
}
|
|
507
493
|
|
|
508
|
-
/** Creates an async event context for an incoming HTTP request/response pair. */
|
|
509
|
-
declare function createHttpContext(data: THttpEventData, options: TEventOptions): <T>(cb: (...a: unknown[]) => T) => T;
|
|
510
|
-
/**
|
|
511
|
-
* Wrapper on useEventContext with HTTP event types
|
|
512
|
-
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
513
|
-
*/
|
|
514
|
-
declare function useHttpContext<T extends TEmpty>(): TCtxHelpers<THttpContextStore & T & TGenericContextStore<THttpEventData>>;
|
|
515
|
-
|
|
516
|
-
declare function createWooksResponder(renderer?: TWooksResponseRenderer<any>, errorRenderer?: TWooksResponseRenderer<any>): {
|
|
517
|
-
createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
|
|
518
|
-
respond: (data: unknown) => Promise<unknown> | undefined;
|
|
519
|
-
};
|
|
520
|
-
|
|
521
494
|
/** Configuration options for the WooksHttp adapter. */
|
|
522
495
|
interface TWooksHttpOptions {
|
|
523
496
|
logger?: TConsoleBase;
|
|
524
|
-
eventOptions?: TEventOptions;
|
|
525
497
|
onNotFound?: TWooksHandler;
|
|
526
498
|
router?: TWooksOptions['router'];
|
|
527
499
|
/** Default request body limits applied to every request (overridable per-request via `useRequest()`). */
|
|
528
500
|
requestLimits?: Omit<TRequestLimits, 'perRequest'>;
|
|
501
|
+
/** Custom HttpResponse subclass. Defaults to WooksHttpResponse (HTML/JSON/text error rendering). */
|
|
502
|
+
responseClass?: typeof WooksHttpResponse;
|
|
503
|
+
/** Default headers applied to every response. Use `securityHeaders()` for recommended security headers. */
|
|
504
|
+
defaultHeaders?: Record<string, string | string[]>;
|
|
529
505
|
}
|
|
530
506
|
/** HTTP adapter for Wooks that provides route registration, server lifecycle, and request handling. */
|
|
531
507
|
declare class WooksHttp extends WooksAdapterBase {
|
|
532
508
|
protected opts?: TWooksHttpOptions | undefined;
|
|
533
509
|
protected logger: TConsoleBase;
|
|
534
|
-
protected
|
|
510
|
+
protected ResponseClass: typeof WooksHttpResponse;
|
|
511
|
+
protected eventContextOptions: EventContextOptions;
|
|
535
512
|
constructor(opts?: TWooksHttpOptions | undefined, wooks?: Wooks | WooksAdapterBase);
|
|
536
513
|
/** Registers a handler for all HTTP methods on the given path. */
|
|
537
514
|
all<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
|
|
@@ -549,6 +526,11 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
549
526
|
head<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
|
|
550
527
|
/** Registers an OPTIONS route handler. */
|
|
551
528
|
options<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
|
|
529
|
+
/** Registers an UPGRADE route handler for WebSocket upgrade requests. */
|
|
530
|
+
upgrade<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): wooks.TProstoRouterPathHandle<ParamsType>;
|
|
531
|
+
private wsHandler?;
|
|
532
|
+
/** Register a WebSocket upgrade handler that implements the WooksUpgradeHandler contract. */
|
|
533
|
+
ws(handler: WooksUpgradeHandler): void;
|
|
552
534
|
protected server?: Server;
|
|
553
535
|
/**
|
|
554
536
|
* Starts the http(s) server.
|
|
@@ -584,11 +566,7 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
584
566
|
* @param server Server
|
|
585
567
|
*/
|
|
586
568
|
attachServer(server?: Server): void;
|
|
587
|
-
protected
|
|
588
|
-
createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
|
|
589
|
-
respond: (data: unknown) => Promise<unknown> | undefined;
|
|
590
|
-
};
|
|
591
|
-
protected respond(data: unknown): Promise<unknown> | undefined;
|
|
569
|
+
protected respond(data: unknown, response: HttpResponse, ctx: EventContext): void | Promise<void>;
|
|
592
570
|
/**
|
|
593
571
|
* Returns server callback function
|
|
594
572
|
* that can be passed to any node server:
|
|
@@ -602,7 +580,14 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
602
580
|
* ```
|
|
603
581
|
*/
|
|
604
582
|
getServerCb(): (req: IncomingMessage, res: ServerResponse) => void;
|
|
605
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Returns upgrade callback function for the HTTP server's 'upgrade' event.
|
|
585
|
+
* Creates an HTTP context, seeds it with upgrade data, and routes as method 'UPGRADE'.
|
|
586
|
+
*/
|
|
587
|
+
getUpgradeCb(): (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
|
|
588
|
+
protected processUpgradeHandlers(handlers: TWooksHandler[], ctx: EventContext, socket: Duplex): void | Promise<unknown>;
|
|
589
|
+
protected processHandlers(handlers: TWooksHandler[], ctx: EventContext, response: HttpResponse): void | Promise<unknown>;
|
|
590
|
+
private processAsyncResult;
|
|
606
591
|
}
|
|
607
592
|
/**
|
|
608
593
|
* Creates a new WooksHttp application instance.
|
|
@@ -615,5 +600,76 @@ declare class WooksHttp extends WooksAdapterBase {
|
|
|
615
600
|
*/
|
|
616
601
|
declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
|
|
617
602
|
|
|
618
|
-
|
|
619
|
-
|
|
603
|
+
/** Event kind definition for HTTP requests. Provides typed context slots for `req`, `response`, and `requestLimits`. */
|
|
604
|
+
declare const httpKind: _wooksjs_event_core.EventKind<{
|
|
605
|
+
req: _wooksjs_event_core.SlotMarker<IncomingMessage>;
|
|
606
|
+
response: _wooksjs_event_core.SlotMarker<HttpResponse>;
|
|
607
|
+
requestLimits: _wooksjs_event_core.SlotMarker<TRequestLimits | undefined>;
|
|
608
|
+
}>;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Configuration for `securityHeaders()`. Each option accepts a `string` (override value),
|
|
612
|
+
* `false` (disable), or `undefined` (use default). `strictTransportSecurity` has no default (opt-in only).
|
|
613
|
+
*/
|
|
614
|
+
interface SecurityHeadersOptions {
|
|
615
|
+
/** `Content-Security-Policy` header. Default: `"default-src 'self'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'"`. */
|
|
616
|
+
contentSecurityPolicy?: string | false;
|
|
617
|
+
/** `Cross-Origin-Opener-Policy` header. Default: `'same-origin'`. */
|
|
618
|
+
crossOriginOpenerPolicy?: string | false;
|
|
619
|
+
/** `Cross-Origin-Resource-Policy` header. Default: `'same-origin'`. */
|
|
620
|
+
crossOriginResourcePolicy?: string | false;
|
|
621
|
+
/** `Referrer-Policy` header. Default: `'no-referrer'`. */
|
|
622
|
+
referrerPolicy?: string | false;
|
|
623
|
+
/** `Strict-Transport-Security` header. No default (opt-in only — HSTS is dangerous if not on HTTPS). */
|
|
624
|
+
strictTransportSecurity?: string | false;
|
|
625
|
+
/** `X-Content-Type-Options` header. Default: `'nosniff'`. */
|
|
626
|
+
xContentTypeOptions?: string | false;
|
|
627
|
+
/** `X-Frame-Options` header. Default: `'SAMEORIGIN'`. */
|
|
628
|
+
xFrameOptions?: string | false;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Returns a record of recommended HTTP security headers.
|
|
632
|
+
*
|
|
633
|
+
* Each option accepts a `string` (override value) or `false` (disable).
|
|
634
|
+
* Omitting an option uses the default value.
|
|
635
|
+
*
|
|
636
|
+
* `strictTransportSecurity` is opt-in only (no default) — HSTS is dangerous if not on HTTPS.
|
|
637
|
+
*/
|
|
638
|
+
declare function securityHeaders(opts?: SecurityHeadersOptions): Record<string, string>;
|
|
639
|
+
|
|
640
|
+
/** Options for creating a test HTTP event context. */
|
|
641
|
+
interface TTestHttpContext {
|
|
642
|
+
/** Pre-set route parameters (e.g. `{ id: '42' }`). */
|
|
643
|
+
params?: Record<string, string | string[]>;
|
|
644
|
+
/** Request URL (e.g. `/api/users?page=1`). */
|
|
645
|
+
url: string;
|
|
646
|
+
/** Request headers. */
|
|
647
|
+
headers?: Record<string, string>;
|
|
648
|
+
/** HTTP method (default: `'GET'`). */
|
|
649
|
+
method?: string;
|
|
650
|
+
/** Custom request body limits. */
|
|
651
|
+
requestLimits?: TRequestLimits;
|
|
652
|
+
/** Pre-seed the raw body for body-parsing tests. */
|
|
653
|
+
rawBody?: string | Buffer$1;
|
|
654
|
+
/** Default headers to pre-populate on the response (e.g. from `securityHeaders()`). */
|
|
655
|
+
defaultHeaders?: Record<string, string | string[]>;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Creates a fully initialized HTTP event context for testing.
|
|
659
|
+
*
|
|
660
|
+
* Sets up an `EventContext` with a fake `IncomingMessage`, `HttpResponse`, route params,
|
|
661
|
+
* and optional pre-seeded body. Returns a runner function that executes callbacks inside the context scope.
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* ```ts
|
|
665
|
+
* const run = prepareTestHttpContext({ url: '/users/42', params: { id: '42' } })
|
|
666
|
+
* run(() => {
|
|
667
|
+
* const { params } = useRouteParams()
|
|
668
|
+
* expect(params.id).toBe('42')
|
|
669
|
+
* })
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
declare function prepareTestHttpContext(options: TTestHttpContext): <T>(cb: (...a: any[]) => T) => T;
|
|
673
|
+
|
|
674
|
+
export { DEFAULT_LIMITS, EHttpStatusCode, HttpError, HttpResponse, WooksHttp, WooksHttpResponse, WooksURLSearchParams, createHttpApp, createHttpContext, httpKind, httpStatusCodes, prepareTestHttpContext, rawBodySlot, renderCacheControl, securityHeaders, useAccept, useAuthorization, useCookies, useHeaders, useHttpContext, useRequest, useResponse, useUrlParams };
|
|
675
|
+
export type { KnownAcceptType, KnownAuthType, SecurityHeadersOptions, TCacheControl, TCookieAttributes, TCookieAttributesInput, THttpEventData, TRequestLimits, TSetCookieData, TTestHttpContext, TWooksErrorBody, TWooksErrorBodyExt, TWooksHttpOptions };
|