@h3ravel/http 11.6.0 → 11.7.0

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/dist/index.d.ts CHANGED
@@ -1,173 +1,58 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
2
  import { Command } from "@h3ravel/musket";
3
- import { DotNestedKeys, DotNestedValue, HttpContext as HttpContext$1, IApplication, IMiddleware, IParamBag, IRequest, IResponse, RequestMethod, RequestObject } from "@h3ravel/shared";
3
+ import { DotNestedKeys, DotNestedValue, HttpContext as HttpContext$1, IApplication, IMiddleware, IParamBag, IRequest, IResponse, RequestMethod, RequestObject, ResponseObject } from "@h3ravel/shared";
4
4
  import { EventHandlerRequest, H3Event, HTTPResponse } from "h3";
5
+ import { DateTime } from "@h3ravel/support";
5
6
  import { Application } from "@h3ravel/core";
6
7
  import { Url } from "@h3ravel/url";
7
8
 
8
- //#region src/Bags/ParamBag.d.ts
9
- /**
10
- * ParamBag is a container for key/value pairs
11
- * for Node/H3 environments.
12
- */
13
- declare class ParamBag implements IParamBag {
14
- protected parameters: RequestObject;
15
- /**
16
- * The current H3 H3Event instance
17
- */
18
- readonly event: H3Event;
19
- constructor(parameters: RequestObject | undefined,
20
- /**
21
- * The current H3 H3Event instance
22
- */
23
- event: H3Event);
24
- /**
25
- * Returns the parameters.
26
- * @
27
- * @param key The name of the parameter to return or null to get them all
28
- *
29
- * @throws BadRequestException if the value is not an array
30
- */
31
- all(key?: string): any;
32
- get(key: string, defaultValue?: any): any;
33
- set(key: string, value: any): void;
34
- /**
35
- * Returns true if the parameter is defined.
36
- *
37
- * @param key
38
- */
39
- has(key: string): boolean;
40
- /**
41
- * Removes a parameter.
42
- *
43
- * @param key
44
- */
45
- remove(key: string): void;
46
- /**
47
- *
48
- * Returns the parameter as string.
49
- *
50
- * @param key
51
- * @param defaultValue
52
- * @throws UnexpectedValueException if the value cannot be converted to string
53
- * @returns
54
- */
55
- getString(key: string, defaultValue?: string): string;
56
- /**
57
- * Returns the parameter value converted to integer.
58
- *
59
- * @param key
60
- * @param defaultValue
61
- * @throws UnexpectedValueException if the value cannot be converted to integer
62
- */
63
- getInt(key: string, defaultValue?: number): number;
64
- /**
65
- * Returns the parameter value converted to boolean.
66
- *
67
- * @param key
68
- * @param defaultValue
69
- * @throws UnexpectedValueException if the value cannot be converted to a boolean
70
- */
71
- getBoolean(key: string, defaultValue?: boolean): boolean;
72
- /**
73
- * Returns the alphabetic characters of the parameter value.
74
- *
75
- * @param key
76
- * @param defaultValue
77
- * @throws UnexpectedValueException if the value cannot be converted to string
78
- */
79
- getAlpha(key: string, defaultValue?: string): string;
80
- /**
81
- * Returns the alphabetic characters and digits of the parameter value.
82
- *
83
- * @param key
84
- * @param defaultValue
85
- * @throws UnexpectedValueException if the value cannot be converted to string
86
- */
87
- getAlnum(key: string, defaultValue?: string): string;
9
+ //#region src/Commands/FireCommand.d.ts
10
+ declare class FireCommand extends Command {
88
11
  /**
89
- * Returns the digits of the parameter value.
12
+ * The name and signature of the console command.
90
13
  *
91
- * @param key
92
- * @param defaultValue
93
- * @throws UnexpectedValueException if the value cannot be converted to string
94
- * @returns
95
- **/
96
- getDigits(key: string, defaultValue?: string): string;
97
- /**
98
- * Returns the parameter keys.
99
- */
100
- keys(): string[];
101
- /**
102
- * Replaces the current parameters by a new set.
103
- */
104
- replace(parameters?: RequestObject): void;
105
- /**
106
- * Adds parameters.
107
- */
108
- add(parameters?: RequestObject): void;
109
- /**
110
- * Returns the number of parameters.
14
+ * @var string
111
15
  */
112
- count(): number;
16
+ protected signature: string;
113
17
  /**
114
- * Returns an iterator for parameters.
18
+ * The console command description.
115
19
  *
116
- * @returns
20
+ * @var string
117
21
  */
118
- [Symbol.iterator](): ArrayIterator<[string, any]>;
22
+ protected description: string;
23
+ handle(): Promise<void>;
24
+ protected fire(): Promise<void>;
119
25
  }
120
26
  //#endregion
121
- //#region src/UploadedFile.d.ts
122
- declare class UploadedFile {
123
- originalName: string;
124
- mimeType: string;
125
- size: number;
126
- content: File;
127
- constructor(originalName: string, mimeType: string, size: number, content: File);
128
- static createFromBase(file: File): UploadedFile;
129
- /**
130
- * Save to disk (Node environment only)
131
- */
132
- moveTo(destination: string): Promise<void>;
27
+ //#region src/Contracts/HttpContract.d.ts
28
+ type CacheOptions = Partial<{
29
+ must_revalidate: boolean;
30
+ no_cache: boolean;
31
+ no_store: boolean;
32
+ no_transform: boolean;
33
+ public: boolean;
34
+ private: boolean;
35
+ proxy_revalidate: boolean;
36
+ max_age: number;
37
+ s_maxage: number;
38
+ immutable: boolean;
39
+ stale_while_revalidate: number;
40
+ stale_if_error: number;
41
+ last_modified: string | Date;
42
+ etag: string;
43
+ }>;
44
+ //#endregion
45
+ //#region src/Exceptions/BadRequestException.d.ts
46
+ declare class BadRequestException extends Error {
47
+ constructor(message: string);
133
48
  }
134
49
  //#endregion
135
- //#region src/Bags/FileBag.d.ts
136
- type FileInput = UploadedFile | File | null | undefined;
137
- /**
138
- * FileBag is a container for uploaded files
139
- * for Node/H3 environments.
140
- */
141
- declare class FileBag extends ParamBag {
142
- protected parameters: Record<string, UploadedFile | UploadedFile[] | null>;
143
- constructor(parameters: Record<string, FileInput | FileInput[]> | undefined,
144
- /**
145
- * The current H3 H3Event instance
146
- */
147
- event: H3Event);
148
- /**
149
- * Replace all stored files.
150
- */
151
- replace(files?: Record<string, FileInput | FileInput[]>): void;
152
- /**
153
- * Set a file or array of files.
154
- */
155
- set(key: string, value: FileInput | FileInput[]): void;
156
- /**
157
- * Add multiple files.
158
- */
159
- add(files?: Record<string, FileInput | FileInput[]>): void;
160
- /**
161
- * Get all stored files.
162
- */
163
- all(): Record<string, UploadedFile | UploadedFile[] | null>;
164
- /**
165
- * Normalize file input into UploadedFile instances.
166
- */
167
- protected convertFileInformation(file: FileInput): UploadedFile | null;
50
+ //#region src/Exceptions/ConflictingHeadersException.d.ts
51
+ declare class ConflictingHeadersException extends Error {
52
+ constructor(message: string);
168
53
  }
169
54
  //#endregion
170
- //#region src/Bags/HeaderBag.d.ts
55
+ //#region src/Utilities/HeaderBag.d.ts
171
56
  /**
172
57
  * HeaderBag — A container for HTTP headers
173
58
  * for Node/H3 environments.
@@ -176,6 +61,7 @@ declare class HeaderBag implements Iterable<[string, (string | null)[]]> {
176
61
  protected static readonly UPPER = "_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
177
62
  protected static readonly LOWER = "-abcdefghijklmnopqrstuvwxyz";
178
63
  protected headers: Record<string, (string | null)[]>;
64
+ protected headerNames: Record<string, string>;
179
65
  protected cacheControl: Record<string, string | boolean>;
180
66
  constructor(headers?: Record<string, string | string[] | null>);
181
67
  /**
@@ -190,7 +76,7 @@ declare class HeaderBag implements Iterable<[string, (string | null)[]]> {
190
76
  * @param key
191
77
  * @returns
192
78
  */
193
- all(key?: string): Record<string, (string | null)[]> | (string | null)[];
79
+ all<K extends string | undefined>(key?: K): K extends string ? (string | null)[] : Record<string, (string | null)[]>;
194
80
  /**
195
81
  * Returns header keys
196
82
  *
@@ -251,7 +137,7 @@ declare class HeaderBag implements Iterable<[string, (string | null)[]]> {
251
137
  * @param defaultValue
252
138
  * @returns
253
139
  */
254
- getDate(key: string, defaultValue?: Date | null): Date | null;
140
+ getDate(key: string, defaultValue?: Date | null): DateTime | undefined;
255
141
  /**
256
142
  * Adds a Cache-Control directive
257
143
  *
@@ -315,163 +201,455 @@ declare class HeaderBag implements Iterable<[string, (string | null)[]]> {
315
201
  [Symbol.iterator](): Iterator<[string, (string | null)[]]>;
316
202
  }
317
203
  //#endregion
318
- //#region src/Bags/InputBag.d.ts
204
+ //#region src/Utilities/Cookie.d.ts
319
205
  /**
320
- * InputBag is a container for user input values
321
- * (e.g., query params, body, cookies)
206
+ * Represents a Cookie
207
+ */
208
+ declare class Cookie {
209
+ private name;
210
+ private value?;
211
+ private domain?;
212
+ private secure?;
213
+ private httpOnly;
214
+ static readonly SAMESITE_NONE = "none";
215
+ static readonly SAMESITE_LAX = "lax";
216
+ static readonly SAMESITE_STRICT = "strict";
217
+ private expire;
218
+ private path;
219
+ private sameSite?;
220
+ private raw;
221
+ private partitioned;
222
+ private secureDefault;
223
+ private static readonly RESERVED_CHARS_LIST;
224
+ private static readonly RESERVED_CHARS_FROM;
225
+ private static readonly RESERVED_CHARS_TO;
226
+ constructor(name: string, value?: string | null | undefined, expire?: number | string | Date, path?: string, domain?: string | null | undefined, secure?: boolean | null | undefined, httpOnly?: boolean, raw?: boolean, sameSite?: string | null, partitioned?: boolean);
227
+ /**
228
+ * Create a Cookie instance from a Set-Cookie header string.
229
+ */
230
+ static fromString(cookie: string, decode?: boolean): Cookie;
231
+ /**
232
+ * Convert various expiration formats into a timestamp (seconds)
233
+ */
234
+ private static expiresTimestamp;
235
+ private clone;
236
+ withValue(value: string | null): Cookie;
237
+ withDomain(domain: string | null): Cookie;
238
+ withPath(path: string | null): Cookie;
239
+ withSecure(secure?: boolean): Cookie;
240
+ withHttpOnly(httpOnly?: boolean): Cookie;
241
+ withRaw(raw?: boolean): Cookie;
242
+ withSameSite(sameSite?: string | null): Cookie;
243
+ withPartitioned(partitioned?: boolean): Cookie;
244
+ withExpires(expire: number | string | Date): Cookie;
245
+ getName(): string;
246
+ getValue(): string | undefined | null;
247
+ getDomain(): string | undefined | null;
248
+ getPath(): string;
249
+ getExpiresTime(): number;
250
+ getMaxAge(): number;
251
+ /**
252
+ * Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
253
+ */
254
+ isSecure(): boolean;
255
+ isHttpOnly(): boolean;
256
+ isRaw(): boolean;
257
+ getSameSite(): string | undefined | null;
258
+ isPartitioned(): boolean;
259
+ /**
260
+ * Whether this cookie is about to be cleared.
261
+ */
262
+ isCleared(): boolean;
263
+ /**
264
+ * Convert the cookie to a Set-Cookie header string.
265
+ */
266
+ toString(): string;
267
+ /**
268
+ * @param bool $default The default value of the "secure" flag when it is set to null
269
+ */
270
+ setSecureDefault(defaultValue: boolean): void;
271
+ }
272
+ //#endregion
273
+ //#region src/Utilities/ResponseHeaderBag.d.ts
274
+ /**
275
+ * ResponseHeaderBag is a container for Response HTTP headers.
322
276
  * for Node/H3 environments.
323
277
  */
324
- declare class InputBag extends ParamBag {
325
- constructor(inputs: RequestObject | undefined,
278
+ declare class ResponseHeaderBag extends HeaderBag {
279
+ static readonly COOKIES_FLAT = "flat";
280
+ static readonly COOKIES_ARRAY = "array";
281
+ static readonly DISPOSITION_ATTACHMENT = "attachment";
282
+ static readonly DISPOSITION_INLINE = "inline";
283
+ protected computedCacheControl: Record<string, string | boolean>;
284
+ protected cookies: Record<string, Record<string, Record<string, Cookie>>>;
285
+ protected headerNames: Record<string, string>;
286
+ constructor(
326
287
  /**
327
288
  * The current H3 H3Event instance
328
289
  */
329
290
  event: H3Event);
330
291
  /**
331
- * Returns a scalar input value by name.
332
- *
333
- * @param key
334
- * @param defaultValue
335
- * @throws BadRequestException if the input contains a non-scalar value
336
- * @returns
292
+ * Returns the headers with original capitalizations.
337
293
  */
338
- get<T extends string | number | boolean | null>(key: string, defaultValue?: T | null): T | string | number | boolean | null;
294
+ allPreserveCase(): Record<string, string[]>;
295
+ allPreserveCaseWithoutCookies(): Record<string, string[]>;
296
+ replace(headers?: Record<string, string | string[]>): void;
297
+ all<K extends string | undefined>(key?: K): K extends string ? (string | null)[] : Record<string, (string | null)[]>;
298
+ set(key: string, values: string | string[] | null, replace?: boolean): void;
299
+ remove(key: string): void;
300
+ hasCacheControlDirective(key: string): boolean;
301
+ getCacheControlDirective(key: string): boolean | string | null;
302
+ setCookie(cookie: Cookie): void;
303
+ removeCookie(name: string, path?: string, domain?: string | null): void;
339
304
  /**
340
- * Replaces all current input values.
341
- *
342
- * @param inputs
343
- * @returns
305
+ * @throws {Error} if format is invalid
344
306
  */
345
- replace(inputs?: RequestObject): void;
307
+ getCookies(format?: string): Cookie[] | Record<string, any>;
308
+ clearCookie(name: string, path?: string, domain?: string | null, secure?: boolean, httpOnly?: boolean, sameSite?: string | null, partitioned?: boolean): void;
309
+ makeDisposition(disposition: string, filename: string, fallback?: string): string;
310
+ protected computeCacheControlValue(): string;
311
+ private initDate;
312
+ }
313
+ //#endregion
314
+ //#region src/Utilities/HttpResponse.d.ts
315
+ declare class HttpResponse {
346
316
  /**
347
- * Adds multiple input values.
348
- *
349
- * @param inputs
350
- * @returns
317
+ * The current H3 H3Event instance
351
318
  */
352
- add(inputs?: RequestObject): void;
319
+ protected readonly event: H3Event;
320
+ protected statusCode: number;
321
+ protected headers: ResponseHeaderBag;
322
+ protected content: any;
323
+ protected version: string;
324
+ protected statusText: string;
325
+ protected charset?: string;
353
326
  /**
354
- * Sets an input by name.
355
- *
356
- * @param key
357
- * @param value
358
- * @throws TypeError if value is not scalar or array
359
- * @returns
327
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
360
328
  */
361
- set(key: string, value: any): void;
329
+ private HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES;
362
330
  /**
363
- * Returns true if a key exists.
364
- *
365
- * @param key
366
- * @returns
331
+ * The exception that triggered the error response (if applicable).
367
332
  */
368
- has(key: string): boolean;
333
+ exception?: Error;
369
334
  /**
370
- * Returns all parameters.
371
- *
372
- * @returns
335
+ * Tracks headers already sent in informational responses.
373
336
  */
374
- all(): RequestObject;
337
+ private sentHeaders;
375
338
  /**
376
- * Converts a parameter value to string.
339
+ * Status codes translation table.
377
340
  *
378
- * @param key
379
- * @param defaultValue
380
- * @throws BadRequestException if input contains a non-scalar value
381
- * @returns
341
+ * The list of codes is complete according to the
342
+ * @link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Hypertext Transfer Protocol (HTTP) Status Code Registry
343
+ * (last updated 2021-10-01).
344
+ *
345
+ * Unless otherwise noted, the status code is defined in RFC2616.
382
346
  */
383
- getString(key: string, defaultValue?: string): string;
347
+ static statusTexts: {
348
+ [key: number]: string;
349
+ };
350
+ constructor(
384
351
  /**
385
- * Filters input value with a predicate.
386
- * Mimics PHP’s filter_var() in spirit, but simpler.
387
- *
388
- * @param key
389
- * @param defaultValue
390
- * @param filterFn
391
- * @throws BadRequestException if validation fails
392
- * @returns
352
+ * The current H3 H3Event instance
393
353
  */
394
- filter<T = any>(key: string, defaultValue?: T | null, filterFn?: (value: any) => boolean): T | null;
354
+ event: H3Event);
395
355
  /**
396
- * Returns an enum value by key.
397
- *
398
- * @param key
399
- * @param EnumClass
400
- * @param defaultValue
401
- * @throws BadRequestException if conversion fails
402
- * @returns
356
+ * Set HTTP status code.
403
357
  */
404
- getEnum<T extends Record<string, string | number>>(key: string, EnumClass: T, defaultValue?: T[keyof T] | null): T[keyof T] | null;
358
+ setStatusCode(code: number, text?: string): this;
405
359
  /**
406
- * Removes a key.
407
- *
408
- * @param key
360
+ * Retrieves the status code for the current web response.
409
361
  */
410
- remove(key: string): void;
362
+ getStatusCode(): number;
411
363
  /**
412
- * Returns all keys.
413
- *
414
- * @returns
364
+ * Sets the response charset.
415
365
  */
416
- keys(): string[];
366
+ setCharset(charset: string): this;
417
367
  /**
418
- * Returns number of parameters.
419
- *
420
- * @returns
368
+ * Retrieves the response charset.
421
369
  */
422
- count(): number;
423
- }
424
- //#endregion
425
- //#region src/Bags/ServerBag.d.ts
426
- /**
427
- * ServerBag — a simplified version of Symfony's ServerBag
428
- * for Node/H3 environments.
429
- *
430
- * Responsible for extracting and normalizing HTTP headers
431
- * from the incoming request.
432
- */
433
- declare class ServerBag extends ParamBag {
434
- constructor(parameters: Record<string, string | undefined> | undefined,
370
+ getCharset(): string | undefined;
435
371
  /**
436
- * The current H3 H3Event instance
372
+ * Returns true if the response may safely be kept in a shared (surrogate) cache.
373
+ *
374
+ * Responses marked "private" with an explicit Cache-Control directive are
375
+ * considered uncacheable.
376
+ *
377
+ * Responses with neither a freshness lifetime (Expires, max-age) nor cache
378
+ * validator (Last-Modified, ETag) are considered uncacheable because there is
379
+ * no way to tell when or how to remove them from the cache.
380
+ *
381
+ * Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
382
+ * for example "status codes that are defined as cacheable by default [...]
383
+ * can be reused by a cache with heuristic expiration unless otherwise indicated"
384
+ * (https://tools.ietf.org/html/rfc7231#section-6.1)
385
+ *
386
+ * @final
437
387
  */
438
- event: H3Event);
388
+ isCacheable(): boolean;
439
389
  /**
440
- * Returns all request headers, normalized to uppercase with underscores.
441
- * Example: content-type → CONTENT_TYPE
390
+ * Returns true if the response is "fresh".
391
+ *
392
+ * Fresh responses may be served from cache without any interaction with the
393
+ * origin. A response is considered fresh when it includes a Cache-Control/max-age
394
+ * indicator or Expires header and the calculated age is less than the freshness lifetime.
442
395
  */
443
- getHeaders(): Record<string, string>;
396
+ isFresh(): boolean;
444
397
  /**
445
- * Returns a specific header by name, case-insensitive.
398
+ * Returns true if the response includes headers that can be used to validate
399
+ * the response with the origin server using a conditional GET request.
446
400
  */
447
- get(name: string): string | undefined;
401
+ isValidateable(): boolean;
448
402
  /**
449
- * Returns true if a header exists.
403
+ * Sets the response content.
450
404
  */
451
- has(name: string): boolean;
452
- }
453
- //#endregion
454
- //#region src/Commands/FireCommand.d.ts
455
- declare class FireCommand extends Command {
405
+ setContent(content?: any): this;
456
406
  /**
457
- * The name and signature of the console command.
407
+ * Gets the current response content.
408
+ */
409
+ getContent(): any;
410
+ /**
411
+ * Set a header.
412
+ */
413
+ setHeader(name: string, value: string): this;
414
+ /**
415
+ * Sets the HTTP protocol version (1.0 or 1.1).
416
+ */
417
+ setProtocolVersion(version: string): this;
418
+ /**
419
+ * Gets the HTTP protocol version.
420
+ */
421
+ getProtocolVersion(): string;
422
+ /**
423
+ * Marks the response as "private".
458
424
  *
459
- * @var string
425
+ * It makes the response ineligible for serving other clients.
460
426
  */
461
- protected signature: string;
427
+ setPrivate(): this;
462
428
  /**
463
- * The console command description.
429
+ * Marks the response as "public".
464
430
  *
465
- * @var string
431
+ * It makes the response eligible for serving other clients.
466
432
  */
467
- protected description: string;
468
- handle(): Promise<void>;
469
- protected fire(): Promise<void>;
433
+ setPublic(): this;
434
+ /**
435
+ * Returns the Date header as a DateTime instance.
436
+ * @throws {RuntimeException} When the header is not parseable
437
+ */
438
+ getDate(): DateTime | undefined;
439
+ /**
440
+ * Returns the age of the response in seconds.
441
+ *
442
+ * @final
443
+ */
444
+ getAge(): number;
445
+ /**
446
+ * Marks the response stale by setting the Age header to be equal to the maximum age of the response.
447
+ */
448
+ expire(): this;
449
+ /**
450
+ * Returns the value of the Expires header as a DateTime instance.
451
+ *
452
+ * @final
453
+ */
454
+ getExpires(): DateTime | undefined;
455
+ /**
456
+ * Returns the number of seconds after the time specified in the response's Date
457
+ * header when the response should no longer be considered fresh.
458
+ *
459
+ * First, it checks for a s-maxage directive, then a max-age directive, and then it falls
460
+ * back on an expires header. It returns null when no maximum age can be established.
461
+ */
462
+ getMaxAge(): number | undefined;
463
+ /**
464
+ * Sets the number of seconds after which the response should no longer be considered fresh.
465
+ *
466
+ * This method sets the Cache-Control max-age directive.
467
+ */
468
+ setMaxAge(value: number): this;
469
+ /**
470
+ * Sets the number of seconds after which the response should no longer be returned by shared caches when backend is down.
471
+ *
472
+ * This method sets the Cache-Control stale-if-error directive.
473
+ */
474
+ setStaleIfError(value: number): this;
475
+ /**
476
+ * Sets the number of seconds after which the response should no longer return stale content by shared caches.
477
+ *
478
+ * This method sets the Cache-Control stale-while-revalidate directive.
479
+ */
480
+ setStaleWhileRevalidate(value: number): this;
481
+ /**
482
+ * Returns the response's time-to-live in seconds.
483
+ *
484
+ * It returns null when no freshness information is present in the response.
485
+ *
486
+ * When the response's TTL is 0, the response may not be served from cache without first
487
+ * revalidating with the origin.
488
+ *
489
+ * @final
490
+ */
491
+ getTtl(): number | undefined;
492
+ /**
493
+ * Sets the response's time-to-live for shared caches in seconds.
494
+ *
495
+ * This method adjusts the Cache-Control/s-maxage directive.
496
+ */
497
+ setTtl(seconds: number): this;
498
+ /**
499
+ * Sets the response's time-to-live for private/client caches in seconds.
500
+ *
501
+ * This method adjusts the Cache-Control/max-age directive.
502
+ */
503
+ setClientTtl(seconds: number): this;
504
+ /**
505
+ * Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
506
+ *
507
+ * This method sets the Cache-Control s-maxage directive.
508
+ */
509
+ setSharedMaxAge(value: number): this;
510
+ /**
511
+ * Returns the Last-Modified HTTP header as a DateTime instance.
512
+ *
513
+ * @throws \RuntimeException When the HTTP header is not parseable
514
+ *
515
+ * @final
516
+ */
517
+ getLastModified(): DateTime | undefined;
518
+ /**
519
+ * Sets the Last-Modified HTTP header with a DateTime instance.
520
+ *
521
+ * Passing null as value will remove the header.
522
+ *
523
+ * @return $this
524
+ *
525
+ * @final
526
+ */
527
+ setLastModified(date?: DateTime | Date | string): this;
528
+ /**
529
+ * Returns the literal value of the ETag HTTP header.
530
+ */
531
+ getEtag(): string | null;
532
+ /**
533
+ * Sets the ETag value.
534
+ *
535
+ * @param etag The ETag unique identifier or null to remove the header
536
+ * @param weak Whether you want a weak ETag or not
537
+ */
538
+ setEtag(etag?: string, weak?: boolean): this;
539
+ /**
540
+ * Sets the response's cache headers (validation and/or expiration).
541
+ *
542
+ * Available options are: must_revalidate, no_cache, no_store, no_transform, public, private, proxy_revalidate, max_age, s_maxage, immutable, last_modified and etag.
543
+ *
544
+ * @throws {InvalidArgumentException}
545
+ */
546
+ setCache(options: CacheOptions): this;
547
+ /**
548
+ * Modifies the response so that it conforms to the rules defined for a 304 status code.
549
+ *
550
+ * This sets the status, removes the body, and discards any headers
551
+ * that MUST NOT be included in 304 responses.
552
+ * @see https://tools.ietf.org/html/rfc2616#section-10.3.5
553
+ */
554
+ setNotModified(): this;
555
+ /**
556
+ * Add an array of headers to the response.
557
+ *
558
+ */
559
+ withHeaders(headers: HeaderBag | ResponseObject): this;
560
+ /**
561
+ * Set the exception to attach to the response.
562
+ */
563
+ withException(e: Error): this;
564
+ /**
565
+ * Throws the response in a HttpResponseException instance.
566
+ *
567
+ * @throws {HttpResponseException}
568
+ */
569
+ throwResponse(): void;
570
+ /**
571
+ * Is response invalid?
572
+ *
573
+ * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
574
+ */
575
+ isInvalid(): boolean;
576
+ /**
577
+ * Is response informative?
578
+ */
579
+ isInformational(): boolean;
580
+ /**
581
+ * Is response successful?
582
+ */
583
+ isSuccessful(): boolean;
584
+ /**
585
+ * Is the response a redirect?
586
+ */
587
+ isRedirection(): boolean;
588
+ /**
589
+ * Is there a client error?
590
+ */
591
+ isClientError(): boolean;
592
+ /**
593
+ * Was there a server side error?
594
+ */
595
+ isServerError(): boolean;
596
+ /**
597
+ * Is the response OK?
598
+ */
599
+ isOk(): boolean;
600
+ /**
601
+ * Is the response forbidden?
602
+ */
603
+ isForbidden(): boolean;
604
+ /**
605
+ * Is the response a not found error?
606
+ */
607
+ isNotFound(): boolean;
608
+ /**
609
+ * Is the response a redirect of some form?
610
+ */
611
+ isRedirect(location?: string | null): boolean;
612
+ /**
613
+ * Is the response empty?
614
+ */
615
+ isEmpty(): boolean;
616
+ /**
617
+ * Apply headers before sending response.
618
+ */
619
+ sendHeaders(statusCode?: number): this;
620
+ /**
621
+ * Prepares the Response before it is sent to the client.
622
+ *
623
+ * This method tweaks the Response to ensure that it is
624
+ * compliant with RFC 2616. Most of the changes are based on
625
+ * the Request that is "associated" with this Response.
626
+ **/
627
+ prepare(request: Request): this;
628
+ /**
629
+ * Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
630
+ *
631
+ * @see http://support.microsoft.com/kb/323308
632
+ */
633
+ protected ensureIEOverSSLCompatibility(request: Request): void;
470
634
  }
471
635
  //#endregion
472
- //#region src/Exceptions/BadRequestException.d.ts
473
- declare class BadRequestException extends Error {
474
- constructor(message: string);
636
+ //#region src/Exceptions/HttpResponseException.d.ts
637
+ declare class HttpResponseException extends Error {
638
+ /**
639
+ * The underlying response instance.
640
+ */
641
+ protected response: HttpResponse;
642
+ /**
643
+ * Create a new HTTP response exception instance.
644
+ *
645
+ * @param response
646
+ * @param previous
647
+ */
648
+ constructor(response: HttpResponse, previous?: Error);
649
+ /**
650
+ * Get the underlying response instance.
651
+ */
652
+ getResponse(): HttpResponse;
475
653
  }
476
654
  //#endregion
477
655
  //#region src/Exceptions/SuspiciousOperationException.d.ts
@@ -484,6 +662,20 @@ declare class UnexpectedValueException extends Error {
484
662
  constructor(message: string);
485
663
  }
486
664
  //#endregion
665
+ //#region src/UploadedFile.d.ts
666
+ declare class UploadedFile {
667
+ originalName: string;
668
+ mimeType: string;
669
+ size: number;
670
+ content: File;
671
+ constructor(originalName: string, mimeType: string, size: number, content: File);
672
+ static createFromBase(file: File): UploadedFile;
673
+ /**
674
+ * Save to disk (Node environment only)
675
+ */
676
+ moveTo(destination: string): Promise<void>;
677
+ }
678
+ //#endregion
487
679
  //#region src/FormRequest.d.ts
488
680
  declare class FormRequest {
489
681
  protected dataset: {
@@ -573,73 +765,576 @@ declare class HttpServiceProvider {
573
765
  boot(): void;
574
766
  }
575
767
  //#endregion
576
- //#region src/Request.d.ts
577
- declare class Request implements IRequest {
578
- #private;
768
+ //#region src/Utilities/ParamBag.d.ts
769
+ /**
770
+ * ParamBag is a container for key/value pairs
771
+ * for Node/H3 environments.
772
+ */
773
+ declare class ParamBag implements IParamBag {
774
+ protected parameters: RequestObject;
775
+ /**
776
+ * The current H3 H3Event instance
777
+ */
778
+ readonly event: H3Event;
779
+ constructor(parameters: RequestObject | undefined,
780
+ /**
781
+ * The current H3 H3Event instance
782
+ */
783
+ event: H3Event);
784
+ /**
785
+ * Returns the parameters.
786
+ * @
787
+ * @param key The name of the parameter to return or null to get them all
788
+ *
789
+ * @throws BadRequestException if the value is not an array
790
+ */
791
+ all(key?: string): any;
792
+ get(key: string, defaultValue?: any): any;
793
+ set(key: string, value: any): void;
794
+ /**
795
+ * Returns true if the parameter is defined.
796
+ *
797
+ * @param key
798
+ */
799
+ has(key: string): boolean;
800
+ /**
801
+ * Removes a parameter.
802
+ *
803
+ * @param key
804
+ */
805
+ remove(key: string): void;
806
+ /**
807
+ *
808
+ * Returns the parameter as string.
809
+ *
810
+ * @param key
811
+ * @param defaultValue
812
+ * @throws UnexpectedValueException if the value cannot be converted to string
813
+ * @returns
814
+ */
815
+ getString(key: string, defaultValue?: string): string;
816
+ /**
817
+ * Returns the parameter value converted to integer.
818
+ *
819
+ * @param key
820
+ * @param defaultValue
821
+ * @throws UnexpectedValueException if the value cannot be converted to integer
822
+ */
823
+ getInt(key: string, defaultValue?: number): number;
824
+ /**
825
+ * Returns the parameter value converted to boolean.
826
+ *
827
+ * @param key
828
+ * @param defaultValue
829
+ * @throws UnexpectedValueException if the value cannot be converted to a boolean
830
+ */
831
+ getBoolean(key: string, defaultValue?: boolean): boolean;
832
+ /**
833
+ * Returns the alphabetic characters of the parameter value.
834
+ *
835
+ * @param key
836
+ * @param defaultValue
837
+ * @throws UnexpectedValueException if the value cannot be converted to string
838
+ */
839
+ getAlpha(key: string, defaultValue?: string): string;
840
+ /**
841
+ * Returns the alphabetic characters and digits of the parameter value.
842
+ *
843
+ * @param key
844
+ * @param defaultValue
845
+ * @throws UnexpectedValueException if the value cannot be converted to string
846
+ */
847
+ getAlnum(key: string, defaultValue?: string): string;
848
+ /**
849
+ * Returns the digits of the parameter value.
850
+ *
851
+ * @param key
852
+ * @param defaultValue
853
+ * @throws UnexpectedValueException if the value cannot be converted to string
854
+ * @returns
855
+ **/
856
+ getDigits(key: string, defaultValue?: string): string;
857
+ /**
858
+ * Returns the parameter keys.
859
+ */
860
+ keys(): string[];
861
+ /**
862
+ * Replaces the current parameters by a new set.
863
+ */
864
+ replace(parameters?: RequestObject): void;
865
+ /**
866
+ * Adds parameters.
867
+ */
868
+ add(parameters?: RequestObject): void;
869
+ /**
870
+ * Returns the number of parameters.
871
+ */
872
+ count(): number;
873
+ /**
874
+ * Returns an iterator for parameters.
875
+ *
876
+ * @returns
877
+ */
878
+ [Symbol.iterator](): ArrayIterator<[string, any]>;
879
+ }
880
+ //#endregion
881
+ //#region src/Utilities/InputBag.d.ts
882
+ /**
883
+ * InputBag is a container for user input values
884
+ * (e.g., query params, body, cookies)
885
+ * for Node/H3 environments.
886
+ */
887
+ declare class InputBag extends ParamBag {
888
+ constructor(inputs: RequestObject | undefined,
889
+ /**
890
+ * The current H3 H3Event instance
891
+ */
892
+ event: H3Event);
893
+ /**
894
+ * Returns a scalar input value by name.
895
+ *
896
+ * @param key
897
+ * @param defaultValue
898
+ * @throws BadRequestException if the input contains a non-scalar value
899
+ * @returns
900
+ */
901
+ get<T extends string | number | boolean | null>(key: string, defaultValue?: T | null): T | string | number | boolean | null;
902
+ /**
903
+ * Replaces all current input values.
904
+ *
905
+ * @param inputs
906
+ * @returns
907
+ */
908
+ replace(inputs?: RequestObject): void;
909
+ /**
910
+ * Adds multiple input values.
911
+ *
912
+ * @param inputs
913
+ * @returns
914
+ */
915
+ add(inputs?: RequestObject): void;
916
+ /**
917
+ * Sets an input by name.
918
+ *
919
+ * @param key
920
+ * @param value
921
+ * @throws TypeError if value is not scalar or array
922
+ * @returns
923
+ */
924
+ set(key: string, value: any): void;
925
+ /**
926
+ * Returns true if a key exists.
927
+ *
928
+ * @param key
929
+ * @returns
930
+ */
931
+ has(key: string): boolean;
932
+ /**
933
+ * Returns all parameters.
934
+ *
935
+ * @returns
936
+ */
937
+ all(): RequestObject;
938
+ /**
939
+ * Converts a parameter value to string.
940
+ *
941
+ * @param key
942
+ * @param defaultValue
943
+ * @throws BadRequestException if input contains a non-scalar value
944
+ * @returns
945
+ */
946
+ getString(key: string, defaultValue?: string): string;
947
+ /**
948
+ * Filters input value with a predicate.
949
+ * Mimics PHP’s filter_var() in spirit, but simpler.
950
+ *
951
+ * @param key
952
+ * @param defaultValue
953
+ * @param filterFn
954
+ * @throws BadRequestException if validation fails
955
+ * @returns
956
+ */
957
+ filter<T = any>(key: string, defaultValue?: T | null, filterFn?: (value: any) => boolean): T | null;
958
+ /**
959
+ * Returns an enum value by key.
960
+ *
961
+ * @param key
962
+ * @param EnumClass
963
+ * @param defaultValue
964
+ * @throws BadRequestException if conversion fails
965
+ * @returns
966
+ */
967
+ getEnum<T extends Record<string, string | number>>(key: string, EnumClass: T, defaultValue?: T[keyof T] | null): T[keyof T] | null;
968
+ /**
969
+ * Removes a key.
970
+ *
971
+ * @param key
972
+ */
973
+ remove(key: string): void;
974
+ /**
975
+ * Returns all keys.
976
+ *
977
+ * @returns
978
+ */
979
+ keys(): string[];
980
+ /**
981
+ * Returns number of parameters.
982
+ *
983
+ * @returns
984
+ */
985
+ count(): number;
986
+ }
987
+ //#endregion
988
+ //#region src/Utilities/FileBag.d.ts
989
+ type FileInput = UploadedFile | File | null | undefined;
990
+ /**
991
+ * FileBag is a container for uploaded files
992
+ * for Node/H3 environments.
993
+ */
994
+ declare class FileBag extends ParamBag {
995
+ protected parameters: Record<string, UploadedFile | UploadedFile[] | null>;
996
+ constructor(parameters: Record<string, FileInput | FileInput[]> | undefined,
997
+ /**
998
+ * The current H3 H3Event instance
999
+ */
1000
+ event: H3Event);
1001
+ /**
1002
+ * Replace all stored files.
1003
+ */
1004
+ replace(files?: Record<string, FileInput | FileInput[]>): void;
1005
+ /**
1006
+ * Set a file or array of files.
1007
+ */
1008
+ set(key: string, value: FileInput | FileInput[]): void;
1009
+ /**
1010
+ * Add multiple files.
1011
+ */
1012
+ add(files?: Record<string, FileInput | FileInput[]>): void;
1013
+ /**
1014
+ * Get all stored files.
1015
+ */
1016
+ all(): Record<string, UploadedFile | UploadedFile[] | null>;
1017
+ /**
1018
+ * Normalize file input into UploadedFile instances.
1019
+ */
1020
+ protected convertFileInformation(file: FileInput): UploadedFile | null;
1021
+ }
1022
+ //#endregion
1023
+ //#region src/Utilities/ServerBag.d.ts
1024
+ /**
1025
+ * ServerBag — a simplified version of Symfony's ServerBag
1026
+ * for Node/H3 environments.
1027
+ *
1028
+ * Responsible for extracting and normalizing HTTP headers
1029
+ * from the incoming request.
1030
+ */
1031
+ declare class ServerBag extends ParamBag {
1032
+ constructor(parameters: Record<string, string | undefined> | undefined,
1033
+ /**
1034
+ * The current H3 H3Event instance
1035
+ */
1036
+ event: H3Event);
1037
+ /**
1038
+ * Returns all request headers, normalized to uppercase with underscores.
1039
+ * Example: content-type → CONTENT_TYPE
1040
+ */
1041
+ getHeaders(): Record<string, string>;
1042
+ /**
1043
+ * Returns a specific header by name, case-insensitive.
1044
+ */
1045
+ get(name: string): string | undefined;
1046
+ /**
1047
+ * Returns true if a header exists.
1048
+ */
1049
+ has(name: string): boolean;
1050
+ }
1051
+ //#endregion
1052
+ //#region src/Utilities/HttpRequest.d.ts
1053
+ declare class HttpRequest {
1054
+ #private;
1055
+ /**
1056
+ * The current H3 H3Event instance
1057
+ */
1058
+ protected readonly event: H3Event;
1059
+ /**
1060
+ * The current app instance
1061
+ */
1062
+ app: Application;
1063
+ HEADER_FORWARDED: number;
1064
+ HEADER_X_FORWARDED_FOR: number;
1065
+ HEADER_X_FORWARDED_HOST: number;
1066
+ HEADER_X_FORWARDED_PROTO: number;
1067
+ HEADER_X_FORWARDED_PORT: number;
1068
+ HEADER_X_FORWARDED_PREFIX: number;
1069
+ HEADER_X_FORWARDED_AWS_ELB: number;
1070
+ HEADER_X_FORWARDED_TRAEFIK: number;
1071
+ METHOD_HEAD: string;
1072
+ METHOD_GET: string;
1073
+ METHOD_POST: string;
1074
+ METHOD_PUT: string;
1075
+ METHOD_PATCH: string;
1076
+ METHOD_DELETE: string;
1077
+ METHOD_PURGE: string;
1078
+ METHOD_OPTIONS: string;
1079
+ METHOD_TRACE: string;
1080
+ METHOD_CONNECT: string;
1081
+ /**
1082
+ * Names for headers that can be trusted when
1083
+ * using trusted proxies.
1084
+ *
1085
+ * The FORWARDED header is the standard as of rfc7239.
1086
+ *
1087
+ * The other headers are non-standard, but widely used
1088
+ * by popular reverse proxies (like Apache mod_proxy or Amazon EC2).
1089
+ */
1090
+ private TRUSTED_HEADERS;
1091
+ private FORWARDED_PARAMS;
1092
+ /**
1093
+ * Parsed request body
1094
+ */
1095
+ body: unknown;
1096
+ protected format?: string;
1097
+ protected formData: FormRequest;
1098
+ private preferredFormat?;
1099
+ private isForwardedValid;
1100
+ private static trustedHeaderSet;
1101
+ /**
1102
+ * Gets route parameters.
1103
+ * @returns An object containing route parameters.
1104
+ */
1105
+ params: NonNullable<H3Event['context']['params']>;
1106
+ /**
1107
+ * Request body parameters (POST).
1108
+ *
1109
+ * @see getPayload() for portability between content types
1110
+ */
1111
+ protected request: InputBag;
1112
+ /**
1113
+ * Uploaded files (FILES).
1114
+ */
1115
+ files: FileBag;
1116
+ /**
1117
+ * Query string parameters (GET).
1118
+ */
1119
+ query: InputBag;
1120
+ /**
1121
+ * Server and execution environment parameters
1122
+ */
1123
+ server: ServerBag;
1124
+ /**
1125
+ * Cookies
1126
+ */
1127
+ cookies: InputBag;
1128
+ /**
1129
+ * The request attributes (parameters parsed from the PATH_INFO, ...).
1130
+ */
1131
+ attributes: ParamBag;
1132
+ /**
1133
+ * Gets the request headers.
1134
+ * @returns An object containing request headers.
1135
+ */
1136
+ headers: HeaderBag;
1137
+ protected content?: ReadableStream | string | false | null;
1138
+ protected static formats?: Record<string, string[]> | undefined | null;
1139
+ protected static trustedProxies: string[];
1140
+ protected static httpMethodParameterOverride: boolean;
1141
+ /**
1142
+ * List of Acceptable Content Types
1143
+ */
1144
+ private acceptableContentTypes;
1145
+ private trustedValuesCache;
1146
+ constructor(
1147
+ /**
1148
+ * The current H3 H3Event instance
1149
+ */
1150
+ event: H3Event,
1151
+ /**
1152
+ * The current app instance
1153
+ */
1154
+ app: Application);
1155
+ /**
1156
+ * Sets the parameters for this request.
1157
+ *
1158
+ * This method also re-initializes all properties.
1159
+ *
1160
+ * @param attributes
1161
+ * @param cookies The COOKIE parameters
1162
+ * @param files The FILES parameters
1163
+ * @param server The SERVER parameters
1164
+ * @param content The raw body data
1165
+ */
1166
+ initialize(): Promise<void>;
1167
+ /**
1168
+ * Gets a list of content types acceptable by the client browser in preferable order.
1169
+ * @returns {string[]}
1170
+ */
1171
+ getAcceptableContentTypes(): string[];
1172
+ /**
1173
+ * Get a URI instance for the request.
1174
+ */
1175
+ getUriInstance(): Url;
1176
+ /**
1177
+ * Checks whether the request is secure or not.
1178
+ *
1179
+ * This method can read the client protocol from the "X-Forwarded-Proto" header
1180
+ * when trusted proxies were set via "setTrustedProxies()".
1181
+ *
1182
+ * The "X-Forwarded-Proto" header must contain the protocol: "https" or "http".
1183
+ */
1184
+ isSecure(): boolean;
1185
+ /**
1186
+ * Returns the value of the requested header.
1187
+ */
1188
+ getHeader(name: string): string | undefined | null;
1189
+ /**
1190
+ * Checks if the request method is of specified type.
1191
+ *
1192
+ * @param method Uppercase request method (GET, POST etc)
1193
+ */
1194
+ isMethod(method: string): boolean;
1195
+ /**
1196
+ * Checks whether or not the method is safe.
1197
+ *
1198
+ * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
1199
+ */
1200
+ isMethodSafe(): boolean;
1201
+ /**
1202
+ * Checks whether or not the method is idempotent.
1203
+ */
1204
+ isMethodIdempotent(): boolean;
1205
+ /**
1206
+ * Checks whether the method is cacheable or not.
1207
+ *
1208
+ * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
1209
+ */
1210
+ isMethodCacheable(): boolean;
1211
+ /**
1212
+ * Returns true if the request is an XMLHttpRequest (AJAX).
1213
+ */
1214
+ isXmlHttpRequest(): boolean;
1215
+ /**
1216
+ * Initializes HTTP request formats.
1217
+ */
1218
+ protected static initializeFormats(): void;
1219
+ /**
1220
+ * Gets the request "intended" method.
1221
+ *
1222
+ * If the X-HTTP-Method-Override header is set, and if the method is a POST,
1223
+ * then it is used to determine the "real" intended HTTP method.
1224
+ *
1225
+ * The _method request parameter can also be used to determine the HTTP method,
1226
+ * but only if enableHttpMethodParameterOverride() has been called.
1227
+ *
1228
+ * The method is always an uppercased string.
1229
+ *
1230
+ * @see getRealMethod()
1231
+ */
1232
+ getMethod(): RequestMethod;
579
1233
  /**
580
- * The current H3 H3Event instance
1234
+ * Gets the preferred format for the response by inspecting, in the following order:
1235
+ * * the request format set using setRequestFormat;
1236
+ * * the values of the Accept HTTP header.
1237
+ *
1238
+ * Note that if you use this method, you should send the "Vary: Accept" header
1239
+ * in the response to prevent any issues with intermediary HTTP caches.
581
1240
  */
582
- private readonly event;
1241
+ getPreferredFormat(defaultValue?: string): string | undefined;
583
1242
  /**
584
- * The current app instance
1243
+ * Gets the format associated with the mime type.
585
1244
  */
586
- app: Application;
1245
+ getFormat(mimeType: string): string | undefined;
587
1246
  /**
588
- * Parsed request body
1247
+ * Gets the request format.
1248
+ *
1249
+ * Here is the process to determine the format:
1250
+ *
1251
+ * * format defined by the user (with setRequestFormat())
1252
+ * * _format request attribute
1253
+ * * $default
1254
+ *
1255
+ * @see getPreferredFormat
589
1256
  */
590
- body: unknown;
1257
+ getRequestFormat(defaultValue?: string): string | undefined;
591
1258
  /**
592
- * Gets route parameters.
593
- * @returns An object containing route parameters.
1259
+ * Sets the request format.
594
1260
  */
595
- params: NonNullable<H3Event['context']['params']>;
1261
+ setRequestFormat(format: string): void;
596
1262
  /**
597
- * All of the converted files for the request.
1263
+ * Gets the "real" request method.
1264
+ *
1265
+ * @see getMethod()
598
1266
  */
599
- protected convertedFiles?: Record<string, UploadedFile | UploadedFile[]>;
1267
+ getRealMethod(): RequestMethod;
600
1268
  /**
601
- * Form data from incoming request.
602
- * @returns The FormRequest object.
1269
+ * Gets the mime type associated with the format.
603
1270
  */
604
- protected formData: FormRequest;
1271
+ getMimeType(format: string): string | undefined;
605
1272
  /**
606
- * Request body parameters (POST).
607
- *
608
- * @see getPayload() for portability between content types
1273
+ * Gets the mime types associated with the format.
609
1274
  */
610
- protected request: InputBag;
1275
+ static getMimeTypes(format: string): string[];
611
1276
  /**
612
- * Uploaded files (FILES).
1277
+ * Gets the list of trusted proxies.
613
1278
  */
614
- files: FileBag;
1279
+ static getTrustedProxies(): string[];
615
1280
  /**
616
- * Query string parameters (GET).
1281
+ * Returns the request body content.
1282
+ *
1283
+ * @param asStream If true, returns a ReadableStream instead of the parsed string
1284
+ * @return {string | ReadableStream | Promise<string | ReadableStream>}
617
1285
  */
618
- query: InputBag;
1286
+ getContent(asStream?: boolean): string | ReadableStream;
619
1287
  /**
620
- * Server and execution environment parameters
1288
+ * Gets a "parameter" value from any bag.
1289
+ *
1290
+ * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
1291
+ * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
1292
+ * public property instead (attributes, query, request).
1293
+ *
1294
+ * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
1295
+ *
1296
+ * @internal use explicit input sources instead
621
1297
  */
622
- server: ServerBag;
1298
+ get(key: string, defaultValue?: any): any;
623
1299
  /**
624
- * Cookies
1300
+ * Indicates whether this request originated from a trusted proxy.
1301
+ *
1302
+ * This can be useful to determine whether or not to trust the
1303
+ * contents of a proxy-specific header.
625
1304
  */
626
- cookies: InputBag;
1305
+ isFromTrustedProxy(): boolean;
627
1306
  /**
628
- * The request attributes (parameters parsed from the PATH_INFO, ...).
1307
+ * This method is rather heavy because it splits and merges headers, and it's called by many other methods such as
1308
+ * getPort(), isSecure(), getHost(), getClientIps(), getBaseUrl() etc. Thus, we try to cache the results for
1309
+ * best performance.
629
1310
  */
630
- attributes: ParamBag;
1311
+ private getTrustedValues;
1312
+ private normalizeAndFilterClientIps;
631
1313
  /**
632
- * Gets the request headers.
633
- * @returns An object containing request headers.
1314
+ * Enables support for the _method request parameter to determine the intended HTTP method.
1315
+ *
1316
+ * Be warned that enabling this feature might lead to CSRF issues in your code.
1317
+ * Check that you are using CSRF tokens when required.
1318
+ * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
1319
+ * and used to send a "PUT" or "DELETE" request via the _method request parameter.
1320
+ * If these methods are not protected against CSRF, this presents a possible vulnerability.
1321
+ *
1322
+ * The HTTP method can only be overridden when the real HTTP method is POST.
634
1323
  */
635
- headers: HeaderBag;
636
- protected content?: ReadableStream | string | false | null;
637
- protected static formats?: Record<string, string[]> | undefined | null;
638
- protected static httpMethodParameterOverride: boolean;
1324
+ static enableHttpMethodParameterOverride(): void;
639
1325
  /**
640
- * List of Acceptable Content Types
1326
+ * Checks whether support for the _method request parameter is enabled.
641
1327
  */
642
- private acceptableContentTypes;
1328
+ static getHttpMethodParameterOverride(): boolean;
1329
+ }
1330
+ //#endregion
1331
+ //#region src/Request.d.ts
1332
+ declare class Request extends HttpRequest implements IRequest {
1333
+ #private;
1334
+ /**
1335
+ * All of the converted files for the request.
1336
+ */
1337
+ protected convertedFiles?: Record<string, UploadedFile | UploadedFile[]>;
643
1338
  constructor(
644
1339
  /**
645
1340
  * The current H3 H3Event instance
@@ -661,18 +1356,6 @@ declare class Request implements IRequest {
661
1356
  * The current app instance
662
1357
  */
663
1358
  app: Application): Promise<Request>;
664
- /**
665
- * Sets the parameters for this request.
666
- *
667
- * This method also re-initializes all properties.
668
- *
669
- * @param attributes
670
- * @param cookies The COOKIE parameters
671
- * @param files The FILES parameters
672
- * @param server The SERVER parameters
673
- * @param content The raw body data
674
- */
675
- initialize(): Promise<void>;
676
1359
  private setBody;
677
1360
  /**
678
1361
  * Retrieve all data from the instance (query + body).
@@ -782,11 +1465,6 @@ declare class Request implements IRequest {
782
1465
  * @returns
783
1466
  */
784
1467
  wantsJson(): boolean;
785
- /**
786
- * Gets a list of content types acceptable by the client browser in preferable order.
787
- * @returns {string[]}
788
- */
789
- getAcceptableContentTypes(): string[];
790
1468
  /**
791
1469
  * Determine if the request is the result of a PJAX call.
792
1470
  *
@@ -800,60 +1478,6 @@ declare class Request implements IRequest {
800
1478
  * @returns {boolean}
801
1479
  */
802
1480
  ajax(): boolean;
803
- /**
804
- * Returns true if the request is an XMLHttpRequest (AJAX).
805
- */
806
- isXmlHttpRequest(): boolean;
807
- /**
808
- * Returns the value of the requested header.
809
- */
810
- getHeader(name: string): string | undefined | null;
811
- /**
812
- * Checks if the request method is of specified type.
813
- *
814
- * @param method Uppercase request method (GET, POST etc)
815
- */
816
- isMethod(method: string): boolean;
817
- /**
818
- * Checks whether or not the method is safe.
819
- *
820
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.1
821
- */
822
- isMethodSafe(): boolean;
823
- /**
824
- * Checks whether or not the method is idempotent.
825
- */
826
- isMethodIdempotent(): boolean;
827
- /**
828
- * Checks whether the method is cacheable or not.
829
- *
830
- * @see https://tools.ietf.org/html/rfc7231#section-4.2.3
831
- */
832
- isMethodCacheable(): boolean;
833
- /**
834
- * Initializes HTTP request formats.
835
- */
836
- protected static initializeFormats(): void;
837
- /**
838
- * Gets the request "intended" method.
839
- *
840
- * If the X-HTTP-Method-Override header is set, and if the method is a POST,
841
- * then it is used to determine the "real" intended HTTP method.
842
- *
843
- * The _method request parameter can also be used to determine the HTTP method,
844
- * but only if enableHttpMethodParameterOverride() has been called.
845
- *
846
- * The method is always an uppercased string.
847
- *
848
- * @see getRealMethod()
849
- */
850
- getMethod(): RequestMethod;
851
- /**
852
- * Gets the "real" request method.
853
- *
854
- * @see getMethod()
855
- */
856
- getRealMethod(): RequestMethod;
857
1481
  /**
858
1482
  * Get the client IP address.
859
1483
  */
@@ -888,46 +1512,10 @@ declare class Request implements IRequest {
888
1512
  * @return {InputBag}
889
1513
  */
890
1514
  protected getInputSource(): InputBag;
891
- /**
892
- * Returns the request body content.
893
- *
894
- * @param asStream If true, returns a ReadableStream instead of the parsed string
895
- * @return {string | ReadableStream | Promise<string | ReadableStream>}
896
- */
897
- getContent(asStream?: boolean): string | ReadableStream;
898
- /**
899
- * Gets a "parameter" value from any bag.
900
- *
901
- * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
902
- * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
903
- * public property instead (attributes, query, request).
904
- *
905
- * Order of precedence: PATH (routing placeholders or custom attributes), GET, POST
906
- *
907
- * @internal use explicit input sources instead
908
- */
909
- get(key: string, defaultValue?: any): any;
910
- /**
911
- * Enables support for the _method request parameter to determine the intended HTTP method.
912
- *
913
- * Be warned that enabling this feature might lead to CSRF issues in your code.
914
- * Check that you are using CSRF tokens when required.
915
- * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered
916
- * and used to send a "PUT" or "DELETE" request via the _method request parameter.
917
- * If these methods are not protected against CSRF, this presents a possible vulnerability.
918
- *
919
- * The HTTP method can only be overridden when the real HTTP method is POST.
920
- */
921
- static enableHttpMethodParameterOverride(): void;
922
- /**
923
- * Checks whether support for the _method request parameter is enabled.
924
- */
925
- static getHttpMethodParameterOverride(): boolean;
926
1515
  /**
927
1516
  * Dump the items.
928
1517
  *
929
1518
  * @param keys
930
- * @return this
931
1519
  */
932
1520
  dump(...keys: any[]): this;
933
1521
  /**
@@ -1033,47 +1621,66 @@ declare class JsonResource<R$1 extends Resource = any> {
1033
1621
  declare function ApiResource(instance: JsonResource): JsonResource<any>;
1034
1622
  //#endregion
1035
1623
  //#region src/Response.d.ts
1036
- declare class Response implements IResponse {
1624
+ declare class Response extends HttpResponse implements IResponse {
1037
1625
  /**
1038
1626
  * The current app instance
1039
1627
  */
1040
1628
  app: Application;
1629
+ constructor(
1041
1630
  /**
1042
1631
  * The current H3 H3Event instance
1043
1632
  */
1044
- private readonly event;
1045
- private statusCode;
1046
- private headers;
1047
- constructor(event: H3Event,
1633
+ event: H3Event,
1048
1634
  /**
1049
1635
  * The current app instance
1050
1636
  */
1051
1637
  app: Application);
1052
1638
  /**
1053
- * Set HTTP status code.
1639
+ * Sends content for the current web response.
1054
1640
  */
1055
- setStatusCode(code: number): this;
1641
+ sendContent(type?: 'html' | 'json' | 'text' | 'xml', parse?: boolean): unknown;
1056
1642
  /**
1057
- * Set a header.
1643
+ * Sends content for the current web response.
1058
1644
  */
1059
- setHeader(name: string, value: string): this;
1060
- html(content: string): HTTPResponse;
1645
+ send(type?: 'html' | 'json' | 'text' | 'xml'): unknown;
1646
+ /**
1647
+ *
1648
+ * @param content The content to serve
1649
+ * @param send if set to true, the content will be returned, instead of the Response instance
1650
+ * @returns
1651
+ */
1652
+ html(content?: string): this;
1653
+ html(content: string, parse: boolean): HTTPResponse;
1061
1654
  /**
1062
1655
  * Send a JSON response.
1063
1656
  */
1064
- json<T = unknown>(data: T): T;
1657
+ json<T = unknown>(data?: T): this;
1658
+ json<T = unknown>(data: T, parse: boolean): T;
1065
1659
  /**
1066
1660
  * Send plain text.
1067
1661
  */
1068
- text(data: string): string;
1662
+ text(content?: string): this;
1663
+ text(content: string, parse: boolean): HTTPResponse;
1664
+ /**
1665
+ * Send plain xml.
1666
+ */
1667
+ xml(data?: string): this;
1668
+ xml(data: string, parse: boolean): HTTPResponse;
1669
+ /**
1670
+ * Build the HTTP Response
1671
+ *
1672
+ * @param contentType
1673
+ * @param data
1674
+ */
1675
+ private httpResponse;
1069
1676
  /**
1070
1677
  * Redirect to another URL.
1071
1678
  */
1072
1679
  redirect(location: string, status?: number, statusText?: string | undefined): HTTPResponse;
1073
1680
  /**
1074
- * Apply headers before sending response.
1681
+ * Dump the response.
1075
1682
  */
1076
- private applyHeaders;
1683
+ dump(): this;
1077
1684
  /**
1078
1685
  * Get the base event
1079
1686
  */
@@ -1081,4 +1688,210 @@ declare class Response implements IResponse {
1081
1688
  getEvent<K extends DotNestedKeys<H3Event>>(key: K): DotNestedValue<H3Event, K>;
1082
1689
  }
1083
1690
  //#endregion
1084
- export { ApiResource, BadRequestException, FileBag, FireCommand, FormRequest, HeaderBag, HttpContext, HttpServiceProvider, InputBag, JsonResource, LogRequests, Middleware, ParamBag, Request, Resource, Response, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile };
1691
+ //#region src/Utilities/HeaderUtility.d.ts
1692
+ /**
1693
+ * HTTP header utility functions .
1694
+ */
1695
+ declare class HeaderUtility {
1696
+ static readonly DISPOSITION_ATTACHMENT = "attachment";
1697
+ static readonly DISPOSITION_INLINE = "inline";
1698
+ private constructor();
1699
+ /**
1700
+ * Splits an HTTP header by one or more separators.
1701
+ *
1702
+ * Example:
1703
+ * HeaderUtility.split('da, en-gb;q=0.8', ',;')
1704
+ * // returns [['da'], ['en-gb', 'q=0.8']]
1705
+ */
1706
+ static split(header: string, separators: string): string[][];
1707
+ /**
1708
+ * Combines an array of arrays into one associative object.
1709
+ * [['foo', 'abc'], ['bar']] => { foo: 'abc', bar: true }
1710
+ */
1711
+ static combine(parts: (string | true)[][]): Record<string, string | boolean>;
1712
+ /**
1713
+ * Joins an associative object into a string for use in an HTTP header.
1714
+ * { foo: 'abc', bar: true, baz: 'a b c' } => 'foo=abc, bar, baz="a b c"'
1715
+ */
1716
+ static toString(assoc: Record<string, string | boolean>, separator: string): string;
1717
+ /**
1718
+ * Encodes a string as a quoted string, if necessary.
1719
+ */
1720
+ static quote(s: string): string;
1721
+ /**
1722
+ * Decodes a quoted string.
1723
+ */
1724
+ static unquote(s: string): string;
1725
+ /**
1726
+ * Generates an HTTP Content-Disposition field-value.
1727
+ *
1728
+ * @see RFC 6266
1729
+ */
1730
+ static makeDisposition(disposition: string, filename: string, filenameFallback?: string): string;
1731
+ /**
1732
+ * Like parse_str(), but preserves dots in variable names.
1733
+ */
1734
+ static parseQuery(query: string, ignoreBrackets?: boolean, separator?: string): Record<string, any>;
1735
+ private static groupParts;
1736
+ }
1737
+ //#endregion
1738
+ //#region src/Utilities/IpUtils.d.ts
1739
+ /**
1740
+ * Http utility functions for IP handling.
1741
+ */
1742
+ declare class IpUtils {
1743
+ static readonly PRIVATE_SUBNETS: string[];
1744
+ private static checkedIps;
1745
+ private constructor();
1746
+ /**
1747
+ * Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.
1748
+ *
1749
+ * @param requestIp
1750
+ * @param ips List of IPs or subnets (can be a string if only a single one)
1751
+ */
1752
+ static checkIp(requestIp?: string, ips?: string | string[]): boolean;
1753
+ /**
1754
+ * Compares two IPv4 addresses or checks if one belongs to a CIDR subnet.
1755
+ *
1756
+ * @param requestIp
1757
+ * @param ip IPv4 address or subnet in CIDR notation
1758
+ *
1759
+ * @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet
1760
+ */
1761
+ static checkIp4(requestIp: string, ip: string): boolean;
1762
+ /**
1763
+ * Compares two IPv6 addresses or checks if one belongs to a CIDR subnet.
1764
+ *
1765
+ * @see https://github.com/dsp/v6tools
1766
+ *
1767
+ * @param requestIp
1768
+ * @param ip IPv6 address or subnet in CIDR notation
1769
+ *
1770
+ * @throws {RuntimeException} When IPV6 support is not enabled
1771
+ */
1772
+ static checkIp6(requestIp: string, ip: string): boolean;
1773
+ /**
1774
+ * Anonymizes an IPv4/IPv6 by zeroing out trailing bytes.
1775
+ *
1776
+ * @param ip
1777
+ * @param v4Bytes
1778
+ * @param v6Bytes
1779
+ */
1780
+ static anonymize(ip: string, v4Bytes?: number, v6Bytes?: number): string;
1781
+ /**
1782
+ * Checks if IP is within private subnets.
1783
+ */
1784
+ static isPrivateIp(requestIp: string): boolean;
1785
+ private static isIPv4;
1786
+ private static isIPv6;
1787
+ private static ipv4ToLong;
1788
+ private static inetPton;
1789
+ private static inetPton4;
1790
+ private static inetPton6;
1791
+ private static inetNtop;
1792
+ private static getCacheResult;
1793
+ private static setCacheResult;
1794
+ }
1795
+ //#endregion
1796
+ //#region src/Utilities/ResponseUtilities.d.ts
1797
+ declare enum ResponseCodes {
1798
+ HTTP_CONTINUE = 100,
1799
+ HTTP_SWITCHING_PROTOCOLS = 101,
1800
+ HTTP_PROCESSING = 102,
1801
+ // RFC2518
1802
+ HTTP_EARLY_HINTS = 103,
1803
+ // RFC8297
1804
+ HTTP_OK = 200,
1805
+ HTTP_CREATED = 201,
1806
+ HTTP_ACCEPTED = 202,
1807
+ HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
1808
+ HTTP_NO_CONTENT = 204,
1809
+ HTTP_RESET_CONTENT = 205,
1810
+ HTTP_PARTIAL_CONTENT = 206,
1811
+ HTTP_MULTI_STATUS = 207,
1812
+ // RFC4918
1813
+ HTTP_ALREADY_REPORTED = 208,
1814
+ // RFC5842
1815
+ HTTP_IM_USED = 226,
1816
+ // RFC3229
1817
+ HTTP_MULTIPLE_CHOICES = 300,
1818
+ HTTP_MOVED_PERMANENTLY = 301,
1819
+ HTTP_FOUND = 302,
1820
+ HTTP_SEE_OTHER = 303,
1821
+ HTTP_NOT_MODIFIED = 304,
1822
+ HTTP_USE_PROXY = 305,
1823
+ HTTP_RESERVED = 306,
1824
+ HTTP_TEMPORARY_REDIRECT = 307,
1825
+ HTTP_PERMANENTLY_REDIRECT = 308,
1826
+ // RFC7238
1827
+ HTTP_BAD_REQUEST = 400,
1828
+ HTTP_UNAUTHORIZED = 401,
1829
+ HTTP_PAYMENT_REQUIRED = 402,
1830
+ HTTP_FORBIDDEN = 403,
1831
+ HTTP_NOT_FOUND = 404,
1832
+ HTTP_METHOD_NOT_ALLOWED = 405,
1833
+ HTTP_NOT_ACCEPTABLE = 406,
1834
+ HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
1835
+ HTTP_REQUEST_TIMEOUT = 408,
1836
+ HTTP_CONFLICT = 409,
1837
+ HTTP_GONE = 410,
1838
+ HTTP_LENGTH_REQUIRED = 411,
1839
+ HTTP_PRECONDITION_FAILED = 412,
1840
+ HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
1841
+ HTTP_REQUEST_URI_TOO_LONG = 414,
1842
+ HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
1843
+ HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
1844
+ HTTP_EXPECTATION_FAILED = 417,
1845
+ HTTP_I_AM_A_TEAPOT = 418,
1846
+ // RFC2324
1847
+ HTTP_MISDIRECTED_REQUEST = 421,
1848
+ // RFC7540
1849
+ HTTP_UNPROCESSABLE_ENTITY = 422,
1850
+ // RFC4918
1851
+ HTTP_LOCKED = 423,
1852
+ // RFC4918
1853
+ HTTP_FAILED_DEPENDENCY = 424,
1854
+ // RFC4918
1855
+ HTTP_TOO_EARLY = 425,
1856
+ // RFC-ietf-httpbis-replay-04
1857
+ HTTP_UPGRADE_REQUIRED = 426,
1858
+ // RFC2817
1859
+ HTTP_PRECONDITION_REQUIRED = 428,
1860
+ // RFC6585
1861
+ HTTP_TOO_MANY_REQUESTS = 429,
1862
+ // RFC6585
1863
+ HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
1864
+ // RFC6585
1865
+ HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
1866
+ // RFC7725
1867
+ HTTP_INTERNAL_SERVER_ERROR = 500,
1868
+ HTTP_NOT_IMPLEMENTED = 501,
1869
+ HTTP_BAD_GATEWAY = 502,
1870
+ HTTP_SERVICE_UNAVAILABLE = 503,
1871
+ HTTP_GATEWAY_TIMEOUT = 504,
1872
+ HTTP_VERSION_NOT_SUPPORTED = 505,
1873
+ HTTP_VARIANT_ALSO_NEGOTIATES_EXPERIMENTAL = 506,
1874
+ // RFC2295
1875
+ HTTP_INSUFFICIENT_STORAGE = 507,
1876
+ // RFC4918
1877
+ HTTP_LOOP_DETECTED = 508,
1878
+ // RFC5842
1879
+ HTTP_NOT_EXTENDED = 510,
1880
+ // RFC2774
1881
+ HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
1882
+ }
1883
+ declare const HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES: CacheOptions;
1884
+ /**
1885
+ * Status codes translation table.
1886
+ *
1887
+ * The list of codes is complete according to the
1888
+ * @link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Hypertext Transfer Protocol (HTTP) Status Code Registry
1889
+ * (last updated 2021-10-01).
1890
+ *
1891
+ * Unless otherwise noted, the status code is defined in RFC2616.
1892
+ */
1893
+ declare const statusTexts: {
1894
+ [key: number]: string;
1895
+ };
1896
+ //#endregion
1897
+ export { ApiResource, BadRequestException, CacheOptions, ConflictingHeadersException, Cookie, FileBag, FireCommand, FormRequest, HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES, HeaderBag, HeaderUtility, HttpContext, HttpRequest, HttpResponse, HttpResponseException, HttpServiceProvider, InputBag, IpUtils, JsonResource, LogRequests, Middleware, ParamBag, Request, Resource, Response, ResponseCodes, ResponseHeaderBag, ServerBag, SuspiciousOperationException, UnexpectedValueException, UploadedFile, statusTexts };