@adonisjs/http-server 8.0.0-next.4 → 8.0.0-next.6

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.
Files changed (56) hide show
  1. package/build/{chunk-BFGF3A5X.js → chunk-7ROFCP6L.js} +1095 -548
  2. package/build/{chunk-ASX56VAK.js → chunk-NQNHMINZ.js} +59 -0
  3. package/build/factories/http_context.d.ts +2 -1
  4. package/build/factories/http_server.d.ts +7 -0
  5. package/build/factories/main.js +31 -5
  6. package/build/factories/qs_parser_factory.d.ts +3 -2
  7. package/build/factories/request.d.ts +1 -0
  8. package/build/factories/response.d.ts +1 -0
  9. package/build/factories/router.d.ts +1 -0
  10. package/build/factories/server_factory.d.ts +1 -0
  11. package/build/factories/url_builder_factory.d.ts +1 -0
  12. package/build/index.d.ts +3 -1
  13. package/build/index.js +87 -37
  14. package/build/src/cookies/client.d.ts +35 -0
  15. package/build/src/cookies/drivers/encrypted.d.ts +13 -0
  16. package/build/src/cookies/drivers/plain.d.ts +9 -0
  17. package/build/src/cookies/drivers/signed.d.ts +13 -0
  18. package/build/src/cookies/parser.d.ts +18 -0
  19. package/build/src/cookies/serializer.d.ts +20 -0
  20. package/build/src/define_config.d.ts +1 -3
  21. package/build/src/define_middleware.d.ts +1 -1
  22. package/build/src/exception_handler.d.ts +72 -31
  23. package/build/src/helpers.d.ts +50 -0
  24. package/build/src/helpers.js +5 -1
  25. package/build/src/http_context/local_storage.d.ts +17 -0
  26. package/build/src/http_context/main.d.ts +8 -0
  27. package/build/src/qs.d.ts +14 -0
  28. package/build/src/redirect.d.ts +27 -11
  29. package/build/src/request.d.ts +109 -10
  30. package/build/src/response.d.ts +399 -203
  31. package/build/src/router/brisk.d.ts +15 -4
  32. package/build/src/router/executor.d.ts +4 -0
  33. package/build/src/router/factories/use_return_value.d.ts +5 -0
  34. package/build/src/router/group.d.ts +17 -0
  35. package/build/src/router/legacy/url_builder.d.ts +7 -0
  36. package/build/src/router/main.d.ts +72 -1
  37. package/build/src/router/matchers.d.ts +3 -0
  38. package/build/src/router/resource.d.ts +33 -0
  39. package/build/src/router/route.d.ts +8 -0
  40. package/build/src/router/signed_url_builder.d.ts +4 -8
  41. package/build/src/router/store.d.ts +9 -0
  42. package/build/src/router/url_builder.d.ts +4 -9
  43. package/build/src/server/factories/middleware_handler.d.ts +10 -1
  44. package/build/src/server/factories/route_finder.d.ts +13 -3
  45. package/build/src/server/factories/write_response.d.ts +9 -2
  46. package/build/src/server/main.d.ts +77 -23
  47. package/build/src/tracing_channels.d.ts +4 -4
  48. package/build/src/types/middleware.d.ts +33 -8
  49. package/build/src/types/qs.d.ts +5 -0
  50. package/build/src/types/request.d.ts +1 -1
  51. package/build/src/types/response.d.ts +14 -6
  52. package/build/src/types/route.d.ts +40 -17
  53. package/build/src/types/server.d.ts +26 -11
  54. package/build/src/types/tracing_channels.d.ts +21 -3
  55. package/build/src/types/url_builder.d.ts +41 -28
  56. package/package.json +15 -13
@@ -7,54 +7,56 @@ import type { Router } from './router/main.ts';
7
7
  import type { HttpContext } from './http_context/main.ts';
8
8
  import type { CastableHeader, CookieOptions, ResponseConfig, ResponseStream } from './types/response.ts';
9
9
  /**
10
- * The response is a wrapper over [ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse)
11
- * streamlining the process of writing response body and automatically setting up appropriate headers.
10
+ * The Response class provides a fluent API for constructing HTTP responses.
11
+ *
12
+ * It wraps Node.js ServerResponse and streamlines the process of writing
13
+ * response body, setting headers, handling cookies, redirects, and streaming.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * response.status(200).json({ message: 'Hello World' })
18
+ * response.redirect('/dashboard')
19
+ * response.download('/path/to/file.pdf')
20
+ * ```
12
21
  */
13
22
  export declare class Response extends Macroable {
14
23
  #private;
15
24
  request: IncomingMessage;
16
25
  response: ServerResponse;
17
26
  /**
18
- * Does response has body set that will written to the
19
- * response socket at the end of the request
27
+ * Indicates whether the response has any content (body, stream, or file) ready to be sent
20
28
  */
21
29
  get hasLazyBody(): boolean;
22
30
  /**
23
- * Find if the response has non-stream content
31
+ * Indicates whether the response has non-stream content set
24
32
  */
25
33
  get hasContent(): boolean;
26
34
  /**
27
- * Returns true when response body is set using "response.stream"
28
- * method
35
+ * Indicates whether the response body is set as a readable stream
29
36
  */
30
37
  get hasStream(): boolean;
31
38
  /**
32
- * Returns true when response body is set using "response.download"
33
- * or "response.attachment" methods
39
+ * Indicates whether the response is configured to stream a file
34
40
  */
35
41
  get hasFileToStream(): boolean;
36
42
  /**
37
- * Returns the response content. Check if the response
38
- * has content using the "hasContent" method
43
+ * The response content data
39
44
  */
40
45
  get content(): [any, boolean, (string | undefined)?] | undefined;
41
46
  /**
42
- * Returns reference to the stream set using "response.stream"
43
- * method
47
+ * The readable stream instance configured for the response
44
48
  */
45
49
  get outgoingStream(): import("stream").Readable | undefined;
46
50
  /**
47
- * Returns reference to the file path set using "response.stream"
48
- * method.
51
+ * Configuration for file streaming including path and etag generation flag
49
52
  */
50
53
  get fileToStream(): {
51
54
  path: string;
52
55
  generateEtag: boolean;
53
56
  } | undefined;
54
57
  /**
55
- * Lazy body is used to set the response body. However, do not
56
- * write it on the socket immediately unless `response.finish`
57
- * is called.
58
+ * Lazy body container that holds response content until ready to send.
59
+ * Contains different types of response data: content, stream, or fileToStream.
58
60
  */
59
61
  lazyBody: Partial<{
60
62
  content: [any, boolean, string?];
@@ -62,68 +64,106 @@ export declare class Response extends Macroable {
62
64
  fileToStream: [string, boolean, ((error: NodeJS.ErrnoException) => [string, number?])?];
63
65
  }>;
64
66
  /**
65
- * The ctx will be set by the context itself. It creates a circular
66
- * reference
67
+ * HTTP context reference (creates circular dependency with HttpContext)
67
68
  */
68
69
  ctx?: HttpContext;
70
+ /**
71
+ * Creates a new Response instance
72
+ *
73
+ * @param request - Node.js IncomingMessage instance
74
+ * @param response - Node.js ServerResponse instance
75
+ * @param encryption - Encryption service for cookie handling
76
+ * @param config - Response configuration settings
77
+ * @param router - Router instance for URL generation
78
+ * @param qs - Query string parser
79
+ */
69
80
  constructor(request: IncomingMessage, response: ServerResponse, encryption: Encryption, config: ResponseConfig, router: Router, qs: Qs);
70
81
  /**
71
- * Returns a boolean telling if response is finished or not.
72
- * Any more attempts to update headers or body will result
73
- * in raised exceptions.
82
+ * Indicates whether the response has been completely sent
74
83
  */
75
84
  get finished(): boolean;
76
85
  /**
77
- * Returns a boolean telling if response headers has been sent or not.
78
- * Any more attempts to update headers will result in raised
79
- * exceptions.
86
+ * Indicates whether response headers have been sent to the client
80
87
  */
81
88
  get headersSent(): boolean;
82
89
  /**
83
- * Returns a boolean telling if response headers and body is written
84
- * or not. When value is `true`, you can feel free to write headers
85
- * and body.
90
+ * Indicates whether the response is still pending (headers and body can still be modified)
86
91
  */
87
92
  get isPending(): boolean;
88
93
  /**
89
- * Writes the body with appropriate response headers. Etag header is set
90
- * when `generateEtag` is set to `true`.
94
+ * Writes the response body with appropriate headers and content type detection
91
95
  *
92
- * Empty body results in `204`.
96
+ * Automatically sets:
97
+ * - Content-Type based on content analysis
98
+ * - Content-Length header
99
+ * - ETag header (if enabled)
100
+ * - Status code 204 for empty bodies
101
+ *
102
+ * @param content - The response content
103
+ * @param generateEtag - Whether to generate ETag header
104
+ * @param jsonpCallbackName - Optional JSONP callback name
93
105
  */
94
106
  protected writeBody(content: any, generateEtag: boolean, jsonpCallbackName?: string): void;
95
107
  /**
96
- * Stream the body to the response and handles cleaning up the stream
108
+ * Streams the response body and handles error cleanup
109
+ *
110
+ * Manages stream lifecycle including:
111
+ * - Error handling with custom callbacks
112
+ * - Proper stream cleanup to prevent memory leaks
113
+ * - Response finalization
114
+ *
115
+ * @param body - The readable stream to pipe
116
+ * @param errorCallback - Optional custom error handler
117
+ * @returns Promise that resolves when streaming is complete
97
118
  */
98
119
  protected streamBody(body: ResponseStream, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): Promise<void>;
99
120
  /**
100
- * Downloads a file by streaming it to the response
121
+ * Streams a file for download with proper headers and caching support
122
+ *
123
+ * Sets appropriate headers:
124
+ * - Last-Modified based on file stats
125
+ * - Content-Type based on file extension
126
+ * - Content-Length from file size
127
+ * - ETag (if enabled)
128
+ *
129
+ * Handles HEAD requests and cache validation (304 responses).
130
+ *
131
+ * @param filePath - Path to the file to stream
132
+ * @param generateEtag - Whether to generate ETag header
133
+ * @param errorCallback - Optional custom error handler
101
134
  */
102
135
  protected streamFileForDownload(filePath: string, generateEtag: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): Promise<void>;
103
136
  /**
104
- * Listen for the event the response is written
105
- * to the TCP socket.
137
+ * Registers a callback to be called when the response is finished
138
+ *
139
+ * The callback is executed when the response has been completely sent.
140
+ * Uses the "on-finished" package internally.
106
141
  *
107
- * Under the hood the callback is registered with
108
- * the "https://github.com/jshttp/on-finished" package
142
+ * @param callback - Function to call when response is finished
109
143
  */
110
144
  onFinish(callback: (err: Error | null, response: ServerResponse) => void): void;
111
145
  /**
112
- * Writes headers with the Node.js res object using the
113
- * response.setHeader method
146
+ * Transfers all buffered headers to the underlying Node.js response object
114
147
  */
115
148
  relayHeaders(): void;
116
149
  /**
117
- * Calls res.writeHead on the Node.js res object.
150
+ * Writes the response status code and headers
151
+ *
152
+ * @param statusCode - Optional status code to set
153
+ * @returns The Response instance for chaining
118
154
  */
119
155
  writeHead(statusCode?: number): this;
120
156
  /**
121
- * Returns the existing value for a given HTTP response
122
- * header.
157
+ * Gets the value of a response header
158
+ *
159
+ * @param key - Header name
160
+ * @returns The header value
123
161
  */
124
162
  getHeader(key: string): import("http").OutgoingHttpHeader | undefined;
125
163
  /**
126
- * Get response headers
164
+ * Gets all response headers as an object
165
+ *
166
+ * @returns Object containing all headers
127
167
  */
128
168
  getHeaders(): {
129
169
  [x: string]: import("http").OutgoingHttpHeader | undefined;
@@ -209,423 +249,579 @@ export declare class Response extends Macroable {
209
249
  "x-xss-protection"?: string | undefined;
210
250
  };
211
251
  /**
212
- * Set header on the response. To `append` values to the existing header, we suggest
213
- * using [[append]] method.
252
+ * Sets a response header (replaces existing value)
214
253
  *
215
- * If `value` is non existy, then header won't be set.
254
+ * @param key - Header name
255
+ * @param value - Header value (ignored if null/undefined)
256
+ * @returns The Response instance for chaining
216
257
  *
217
258
  * @example
218
- * ```js
219
- * response.header('content-type', 'application/json')
259
+ * ```ts
260
+ * response.header('Content-Type', 'application/json')
220
261
  * ```
221
262
  */
222
263
  header(key: string, value: CastableHeader): this;
223
264
  /**
224
- * Append value to an existing header. To replace the value, we suggest using
225
- * [[header]] method.
265
+ * Appends a value to an existing response header
226
266
  *
227
- * If `value` is not existy, then header won't be set.
267
+ * @param key - Header name
268
+ * @param value - Header value to append (ignored if null/undefined)
269
+ * @returns The Response instance for chaining
228
270
  *
229
271
  * @example
230
- * ```js
231
- * response.append('set-cookie', 'username=virk')
272
+ * ```ts
273
+ * response.append('Set-Cookie', 'session=abc123')
232
274
  * ```
233
275
  */
234
276
  append(key: string, value: CastableHeader): this;
235
277
  /**
236
- * Adds HTTP response header, when it doesn't exists already.
278
+ * Sets a header only if it doesn't already exist
279
+ *
280
+ * @param key - Header name
281
+ * @param value - Header value
282
+ * @returns The Response instance for chaining
237
283
  */
238
284
  safeHeader(key: string, value: CastableHeader): this;
239
285
  /**
240
- * Removes the existing response header from being sent.
286
+ * Removes a response header
287
+ *
288
+ * @param key - Header name to remove
289
+ * @returns The Response instance for chaining
241
290
  */
242
291
  removeHeader(key: string): this;
243
292
  /**
244
- * Returns the status code for the response
293
+ * Gets the current response status code
294
+ *
295
+ * @returns The HTTP status code
245
296
  */
246
297
  getStatus(): number;
247
298
  /**
248
- * Set HTTP status code
299
+ * Sets the response status code
300
+ *
301
+ * @param code - HTTP status code
302
+ * @returns The Response instance for chaining
249
303
  */
250
304
  status(code: number): this;
251
305
  /**
252
- * Set's status code only when it's not explictly
253
- * set
306
+ * Sets the status code only if not explicitly set already
307
+ *
308
+ * @param code - HTTP status code
309
+ * @returns The Response instance for chaining
254
310
  */
255
311
  safeStatus(code: number): this;
256
312
  /**
257
- * Set response type by looking up for the mime-type using
258
- * partial types like file extensions.
313
+ * Sets the Content-Type header based on mime type lookup
259
314
  *
260
- * Make sure to read [mime-types](https://www.npmjs.com/package/mime-types) docs
261
- * too.
315
+ * @param type - File extension or mime type
316
+ * @param charset - Optional character encoding
317
+ * @returns The Response instance for chaining
262
318
  *
263
319
  * @example
264
- * ```js
265
- * response.type('.json') // Content-type: application/json
320
+ * ```ts
321
+ * response.type('.json') // Content-Type: application/json
322
+ * response.type('html', 'utf-8') // Content-Type: text/html; charset=utf-8
266
323
  * ```
267
324
  */
268
325
  type(type: string, charset?: string): this;
269
326
  /**
270
- * Set the Vary HTTP header
327
+ * Sets the Vary HTTP header for cache control
328
+ *
329
+ * @param field - Header field name(s) to vary on
330
+ * @returns The Response instance for chaining
271
331
  */
272
332
  vary(field: string | string[]): this;
273
333
  /**
274
- * Set etag by computing hash from the body. This class will set the etag automatically
275
- * when `etag = true` in the defined config object.
334
+ * Sets the ETag header by computing a hash from the response body
276
335
  *
277
- * Use this function, when you want to compute etag manually for some other resons.
336
+ * @param body - The response body to hash
337
+ * @param weak - Whether to generate a weak ETag
338
+ * @returns The Response instance for chaining
278
339
  */
279
340
  setEtag(body: any, weak?: boolean): this;
280
341
  /**
281
- * Set X-Request-Id header by copying the header value from the request if it exists.
342
+ * Sets the X-Request-Id header by copying from the incoming request
282
343
  *
344
+ * @returns The Response instance for chaining
283
345
  */
284
346
  setRequestId(): this;
285
347
  /**
286
- * Returns a boolean telling if the new response etag evaluates same
287
- * as the request header `if-none-match`. In case of `true`, the
288
- * server must return `304` response, telling the browser to
289
- * use the client cache.
348
+ * Checks if the response is fresh (client cache is valid)
290
349
  *
291
- * You won't have to deal with this method directly, since AdonisJs will
292
- * handle this for you when `http.etag = true` inside `config/app.js` file.
350
+ * Compares ETags and modified dates between request and response
351
+ * to determine if a 304 Not Modified response should be sent.
293
352
  *
294
- * However, this is how you can use it manually.
353
+ * @returns True if client cache is fresh, false otherwise
295
354
  *
296
355
  * @example
297
- * ```js
298
- * const responseBody = view.render('some-view')
299
- *
300
- * // sets the HTTP etag header for response
301
- * response.setEtag(responseBody)
302
- *
356
+ * ```ts
357
+ * response.setEtag(content)
303
358
  * if (response.fresh()) {
304
- * response.sendStatus(304)
359
+ * response.status(304).send(null)
305
360
  * } else {
306
- * response.send(responseBody)
361
+ * response.send(content)
307
362
  * }
308
363
  * ```
309
364
  */
310
365
  fresh(): boolean;
311
366
  /**
312
- * Returns the response body. Returns null when response
313
- * body is a stream
367
+ * Gets the response body content
368
+ *
369
+ * @returns The response body or null if not set or is a stream
314
370
  */
315
371
  getBody(): any;
316
372
  /**
317
- * Send the body as response and optionally generate etag. The default value
318
- * is read from `config/app.js` file, using `http.etag` property.
373
+ * Sends the response body with optional ETag generation
319
374
  *
320
- * This method buffers the body if `explicitEnd = true`, which is the default
321
- * behavior and do not change, unless you know what you are doing.
375
+ * @param body - The response body
376
+ * @param generateEtag - Whether to generate ETag header (defaults to config)
322
377
  */
323
378
  send(body: any, generateEtag?: boolean): void;
324
379
  /**
325
- * Alias of [[send]]
380
+ * Sends a JSON response (alias for send)
381
+ *
382
+ * @param body - The response body to serialize as JSON
383
+ * @param generateEtag - Whether to generate ETag header
326
384
  */
327
385
  json(body: any, generateEtag?: boolean): void;
328
386
  /**
329
- * Writes response as JSONP. The callback name is resolved as follows, with priority
330
- * from top to bottom.
387
+ * Sends a JSONP response with callback wrapping
331
388
  *
332
- * 1. Explicitly defined as 2nd Param.
333
- * 2. Fetch from request query string.
334
- * 3. Use the config value `http.jsonpCallbackName` from `config/app.js`.
335
- * 4. Fallback to `callback`.
389
+ * Callback name resolution priority:
390
+ * 1. Explicit callbackName parameter
391
+ * 2. Query string parameter
392
+ * 3. Config value
393
+ * 4. Default "callback"
336
394
  *
337
- * This method buffers the body if `explicitEnd = true`, which is the default
338
- * behavior and do not change, unless you know what you are doing.
395
+ * @param body - The response body
396
+ * @param callbackName - JSONP callback function name
397
+ * @param generateEtag - Whether to generate ETag header
339
398
  */
340
399
  jsonp(body: any, callbackName?: string, generateEtag?: boolean): void;
341
400
  /**
342
- * Pipe stream to the response. This method will gracefully destroy
343
- * the stream, avoiding memory leaks.
344
- *
345
- * If `raiseErrors=false`, then this method will self handle all the exceptions by
346
- * writing a generic HTTP response. To have more control over the error, it is
347
- * recommended to set `raiseErrors=true` and wrap this function inside a
348
- * `try/catch` statement.
401
+ * Pipes a readable stream to the response with graceful error handling
349
402
  *
350
- * Streaming a file from the disk and showing 404 when file is missing.
403
+ * @param body - The readable stream to pipe
404
+ * @param errorCallback - Optional custom error handler
351
405
  *
352
406
  * @example
353
- * ```js
354
- * // Errors handled automatically with generic HTTP response
407
+ * ```ts
408
+ * // Auto error handling
355
409
  * response.stream(fs.createReadStream('file.txt'))
356
410
  *
357
- * // Manually handle (note the await call)
358
- * try {
359
- * await response.stream(fs.createReadStream('file.txt'))
360
- * } catch () {
361
- * response.status(404).send('File not found')
362
- * }
411
+ * // Custom error handling
412
+ * response.stream(stream, (error) => {
413
+ * return error.code === 'ENOENT' ? ['Not found', 404] : ['Error', 500]
414
+ * })
363
415
  * ```
364
416
  */
365
417
  stream(body: ResponseStream, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
366
418
  /**
367
- * Download file by streaming it from the file path. This method will setup
368
- * appropriate `Content-type`, `Content-type` and `Last-modified` headers.
419
+ * Downloads a file by streaming it with appropriate headers
369
420
  *
370
- * Unexpected stream errors are handled gracefully to avoid memory leaks.
421
+ * Automatically sets:
422
+ * - Content-Type from file extension
423
+ * - Content-Length from file size
424
+ * - Last-Modified from file stats
425
+ * - ETag (if enabled)
371
426
  *
372
- * If `raiseErrors=false`, then this method will self handle all the exceptions by
373
- * writing a generic HTTP response. To have more control over the error, it is
374
- * recommended to set `raiseErrors=true` and wrap this function inside a
375
- * `try/catch` statement.
427
+ * @param filePath - Path to the file to download
428
+ * @param generateEtag - Whether to generate ETag header
429
+ * @param errorCallback - Optional custom error handler
376
430
  *
377
431
  * @example
378
- * ```js
379
- * // Errors handled automatically with generic HTTP response
380
- * response.download('somefile.jpg')
381
- *
382
- * // Manually handle (note the await call)
383
- * try {
384
- * await response.download('somefile.jpg')
385
- * } catch (error) {
386
- * response.status(error.code === 'ENOENT' ? 404 : 500)
387
- * response.send('Cannot process file')
388
- * }
432
+ * ```ts
433
+ * response.download('/path/to/file.pdf')
434
+ * response.download('/images/photo.jpg', true, (err) => ['Custom error', 500])
389
435
  * ```
390
436
  */
391
437
  download(filePath: string, generateEtag?: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
392
438
  /**
393
- * Download the file by forcing the user to save the file vs displaying it
394
- * within the browser.
439
+ * Forces file download by setting Content-Disposition header
395
440
  *
396
- * Internally calls [[download]]
441
+ * @param filePath - Path to the file to download
442
+ * @param name - Optional filename for download (defaults to original filename)
443
+ * @param disposition - Content-Disposition type (defaults to 'attachment')
444
+ * @param generateEtag - Whether to generate ETag header
445
+ * @param errorCallback - Optional custom error handler
397
446
  */
398
447
  attachment(filePath: string, name?: string, disposition?: string, generateEtag?: boolean, errorCallback?: (error: NodeJS.ErrnoException) => [string, number?]): void;
399
448
  /**
400
- * Set the location header.
449
+ * Sets the Location header for redirects
450
+ *
451
+ * @param url - The URL to redirect to
452
+ * @returns The Response instance for chaining
401
453
  *
402
454
  * @example
403
- * ```js
404
- * response.location('/login')
455
+ * ```ts
456
+ * response.location('/dashboard')
405
457
  * ```
406
458
  */
407
459
  location(url: string): this;
408
460
  /**
409
- * Redirect the request.
461
+ * Redirects the request to a different URL
462
+ *
463
+ * @param path - Optional path to redirect to
464
+ * @param forwardQueryString - Whether to forward current query string
465
+ * @param statusCode - HTTP status code for redirect (default: 302)
466
+ * @returns Redirect instance when called without path, void when redirecting
410
467
  *
411
468
  * @example
412
- * ```js
413
- * response.redirect('/foo')
414
- * response.redirect().toRoute('foo.bar')
469
+ * ```ts
470
+ * response.redirect('/dashboard')
471
+ * response.redirect().toRoute('users.show', { id: 1 })
415
472
  * response.redirect().back()
416
473
  * ```
417
474
  */
418
475
  redirect(): Redirect;
419
476
  redirect(path: string, forwardQueryString?: boolean, statusCode?: number): void;
420
477
  /**
421
- * Abort the request with custom body and a status code. 400 is
422
- * used when status is not defined
478
+ * Aborts the request with a custom response body and status code
479
+ *
480
+ * @param body - Response body for the aborted request
481
+ * @param status - HTTP status code (defaults to 400)
482
+ * @throws Always throws an HTTP exception
423
483
  */
424
484
  abort(body: any, status?: number): never;
425
485
  /**
426
- * Abort the request with custom body and a status code when
427
- * passed condition returns `true`
486
+ * Conditionally aborts the request if the condition is truthy
487
+ *
488
+ * @param condition - Condition to evaluate
489
+ * @param body - Response body for the aborted request
490
+ * @param status - HTTP status code (defaults to 400)
428
491
  */
429
492
  abortIf(condition: unknown, body: any, status?: number): asserts condition is undefined | null | false;
430
493
  /**
431
- * Abort the request with custom body and a status code when
432
- * passed condition returns `false`
494
+ * Conditionally aborts the request if the condition is falsy
495
+ *
496
+ * @param condition - Condition to evaluate
497
+ * @param body - Response body for the aborted request
498
+ * @param status - HTTP status code (defaults to 400)
433
499
  */
434
500
  abortUnless<T>(condition: T, body: any, status?: number): asserts condition is Exclude<T, undefined | null | false>;
435
501
  /**
436
- * Set signed cookie as the response header. The inline options overrides
437
- * all options from the config.
502
+ * Sets a signed cookie in the response
503
+ *
504
+ * @param key - Cookie name
505
+ * @param value - Cookie value
506
+ * @param options - Cookie options (overrides config defaults)
507
+ * @returns The Response instance for chaining
438
508
  */
439
509
  cookie(key: string, value: any, options?: Partial<CookieOptions>): this;
440
510
  /**
441
- * Set encrypted cookie as the response header. The inline options overrides
442
- * all options from the config.
511
+ * Sets an encrypted cookie in the response
512
+ *
513
+ * @param key - Cookie name
514
+ * @param value - Cookie value
515
+ * @param options - Cookie options (overrides config defaults)
516
+ * @returns The Response instance for chaining
443
517
  */
444
518
  encryptedCookie(key: string, value: any, options?: Partial<CookieOptions>): this;
445
519
  /**
446
- * Set unsigned cookie as the response header. The inline options overrides
447
- * all options from the config.
520
+ * Sets a plain (unsigned/unencrypted) cookie in the response
521
+ *
522
+ * @param key - Cookie name
523
+ * @param value - Cookie value
524
+ * @param options - Cookie options including encode flag
525
+ * @returns The Response instance for chaining
448
526
  */
449
527
  plainCookie(key: string, value: any, options?: Partial<CookieOptions & {
450
528
  encode: boolean;
451
529
  }>): this;
452
530
  /**
453
- * Clear existing cookie.
531
+ * Clears an existing cookie by setting it to expire
532
+ *
533
+ * @param key - Cookie name to clear
534
+ * @param options - Cookie options (should match original cookie options)
535
+ * @returns The Response instance for chaining
454
536
  */
455
537
  clearCookie(key: string, options?: Partial<CookieOptions>): this;
456
538
  /**
457
- * Finishes the response by writing the lazy body, when `explicitEnd = true`
458
- * and response is already pending.
539
+ * Finalizes and sends the response
459
540
  *
460
- * Calling this method twice or when `explicitEnd = false` is noop.
541
+ * Writes the buffered body (content, stream, or file) to the client.
542
+ * This method is idempotent - calling it multiple times has no effect.
461
543
  */
462
544
  finish(): void;
463
545
  /**
464
- * Shorthand method to finish request with "100" status code
546
+ * Sends a 100 Continue response
465
547
  */
466
548
  continue(): void;
467
549
  /**
468
- * Shorthand method to finish request with "101" status code
550
+ * Sends a 101 Switching Protocols response
469
551
  */
470
552
  switchingProtocols(): void;
471
553
  /**
472
- * Shorthand method to finish request with "200" status code
554
+ * Sends a 200 OK response
555
+ *
556
+ * @param body - Response body
557
+ * @param generateEtag - Whether to generate ETag header
473
558
  */
474
559
  ok(body: any, generateEtag?: boolean): void;
475
560
  /**
476
- * Shorthand method to finish request with "201" status code
561
+ * Sends a 201 Created response
562
+ *
563
+ * @param body - Response body
564
+ * @param generateEtag - Whether to generate ETag header
477
565
  */
478
566
  created(body?: any, generateEtag?: boolean): void;
479
567
  /**
480
- * Shorthand method to finish request with "202" status code
568
+ * Sends a 202 Accepted response
569
+ *
570
+ * @param body - Response body
571
+ * @param generateEtag - Whether to generate ETag header
481
572
  */
482
573
  accepted(body: any, generateEtag?: boolean): void;
483
574
  /**
484
- * Shorthand method to finish request with "203" status code
575
+ * Sends a 203 Non-Authoritative Information response
576
+ *
577
+ * @param body - Response body
578
+ * @param generateEtag - Whether to generate ETag header
485
579
  */
486
580
  nonAuthoritativeInformation(body: any, generateEtag?: boolean): void;
487
581
  /**
488
- * Shorthand method to finish request with "204" status code
582
+ * Sends a 204 No Content response
489
583
  */
490
584
  noContent(): void;
491
585
  /**
492
- * Shorthand method to finish request with "205" status code
586
+ * Sends a 205 Reset Content response
493
587
  */
494
588
  resetContent(): void;
495
589
  /**
496
- * Shorthand method to finish request with "206" status code
590
+ * Sends a 206 Partial Content response
591
+ *
592
+ * @param body - Response body
593
+ * @param generateEtag - Whether to generate ETag header
497
594
  */
498
595
  partialContent(body: any, generateEtag?: boolean): void;
499
596
  /**
500
- * Shorthand method to finish request with "300" status code
597
+ * Sends a 300 Multiple Choices response
598
+ *
599
+ * @param body - Response body
600
+ * @param generateEtag - Whether to generate ETag header
501
601
  */
502
602
  multipleChoices(body?: any, generateEtag?: boolean): void;
503
603
  /**
504
- * Shorthand method to finish request with "301" status code
604
+ * Sends a 301 Moved Permanently response
605
+ *
606
+ * @param body - Response body
607
+ * @param generateEtag - Whether to generate ETag header
505
608
  */
506
609
  movedPermanently(body?: any, generateEtag?: boolean): void;
507
610
  /**
508
- * Shorthand method to finish request with "302" status code
611
+ * Sends a 302 Found (Moved Temporarily) response
612
+ *
613
+ * @param body - Response body
614
+ * @param generateEtag - Whether to generate ETag header
509
615
  */
510
616
  movedTemporarily(body?: any, generateEtag?: boolean): void;
511
617
  /**
512
- * Shorthand method to finish request with "303" status code
618
+ * Sends a 303 See Other response
619
+ *
620
+ * @param body - Response body
621
+ * @param generateEtag - Whether to generate ETag header
513
622
  */
514
623
  seeOther(body?: any, generateEtag?: boolean): void;
515
624
  /**
516
- * Shorthand method to finish request with "304" status code
625
+ * Sends a 304 Not Modified response
626
+ *
627
+ * @param body - Response body
628
+ * @param generateEtag - Whether to generate ETag header
517
629
  */
518
630
  notModified(body?: any, generateEtag?: boolean): void;
519
631
  /**
520
- * Shorthand method to finish request with "305" status code
632
+ * Sends a 305 Use Proxy response
633
+ *
634
+ * @param body - Response body
635
+ * @param generateEtag - Whether to generate ETag header
521
636
  */
522
637
  useProxy(body?: any, generateEtag?: boolean): void;
523
638
  /**
524
- * Shorthand method to finish request with "307" status code
639
+ * Sends a 307 Temporary Redirect response
640
+ *
641
+ * @param body - Response body
642
+ * @param generateEtag - Whether to generate ETag header
525
643
  */
526
644
  temporaryRedirect(body?: any, generateEtag?: boolean): void;
527
645
  /**
528
- * Shorthand method to finish request with "400" status code
646
+ * Sends a 400 Bad Request response
647
+ *
648
+ * @param body - Response body
649
+ * @param generateEtag - Whether to generate ETag header
529
650
  */
530
651
  badRequest(body?: any, generateEtag?: boolean): void;
531
652
  /**
532
- * Shorthand method to finish request with "401" status code
653
+ * Sends a 401 Unauthorized response
654
+ *
655
+ * @param body - Response body
656
+ * @param generateEtag - Whether to generate ETag header
533
657
  */
534
658
  unauthorized(body?: any, generateEtag?: boolean): void;
535
659
  /**
536
- * Shorthand method to finish request with "402" status code
660
+ * Sends a 402 Payment Required response
661
+ *
662
+ * @param body - Response body
663
+ * @param generateEtag - Whether to generate ETag header
537
664
  */
538
665
  paymentRequired(body?: any, generateEtag?: boolean): void;
539
666
  /**
540
- * Shorthand method to finish request with "403" status code
667
+ * Sends a 403 Forbidden response
668
+ *
669
+ * @param body - Response body
670
+ * @param generateEtag - Whether to generate ETag header
541
671
  */
542
672
  forbidden(body?: any, generateEtag?: boolean): void;
543
673
  /**
544
- * Shorthand method to finish request with "404" status code
674
+ * Sends a 404 Not Found response
675
+ *
676
+ * @param body - Response body
677
+ * @param generateEtag - Whether to generate ETag header
545
678
  */
546
679
  notFound(body?: any, generateEtag?: boolean): void;
547
680
  /**
548
- * Shorthand method to finish request with "405" status code
681
+ * Sends a 405 Method Not Allowed response
682
+ *
683
+ * @param body - Response body
684
+ * @param generateEtag - Whether to generate ETag header
549
685
  */
550
686
  methodNotAllowed(body?: any, generateEtag?: boolean): void;
551
687
  /**
552
- * Shorthand method to finish request with "406" status code
688
+ * Sends a 406 Not Acceptable response
689
+ *
690
+ * @param body - Response body
691
+ * @param generateEtag - Whether to generate ETag header
553
692
  */
554
693
  notAcceptable(body?: any, generateEtag?: boolean): void;
555
694
  /**
556
- * Shorthand method to finish request with "407" status code
695
+ * Sends a 407 Proxy Authentication Required response
696
+ *
697
+ * @param body - Response body
698
+ * @param generateEtag - Whether to generate ETag header
557
699
  */
558
700
  proxyAuthenticationRequired(body?: any, generateEtag?: boolean): void;
559
701
  /**
560
- * Shorthand method to finish request with "408" status code
702
+ * Sends a 408 Request Timeout response
703
+ *
704
+ * @param body - Response body
705
+ * @param generateEtag - Whether to generate ETag header
561
706
  */
562
707
  requestTimeout(body?: any, generateEtag?: boolean): void;
563
708
  /**
564
- * Shorthand method to finish request with "409" status code
709
+ * Sends a 409 Conflict response
710
+ *
711
+ * @param body - Response body
712
+ * @param generateEtag - Whether to generate ETag header
565
713
  */
566
714
  conflict(body?: any, generateEtag?: boolean): void;
567
715
  /**
568
- * Shorthand method to finish request with "401" status code
716
+ * Sends a 410 Gone response
717
+ *
718
+ * @param body - Response body
719
+ * @param generateEtag - Whether to generate ETag header
569
720
  */
570
721
  gone(body?: any, generateEtag?: boolean): void;
571
722
  /**
572
- * Shorthand method to finish request with "411" status code
723
+ * Sends a 411 Length Required response
724
+ *
725
+ * @param body - Response body
726
+ * @param generateEtag - Whether to generate ETag header
573
727
  */
574
728
  lengthRequired(body?: any, generateEtag?: boolean): void;
575
729
  /**
576
- * Shorthand method to finish request with "412" status code
730
+ * Sends a 412 Precondition Failed response
731
+ *
732
+ * @param body - Response body
733
+ * @param generateEtag - Whether to generate ETag header
577
734
  */
578
735
  preconditionFailed(body?: any, generateEtag?: boolean): void;
579
736
  /**
580
- * Shorthand method to finish request with "413" status code
737
+ * Sends a 413 Payload Too Large response
738
+ *
739
+ * @param body - Response body
740
+ * @param generateEtag - Whether to generate ETag header
581
741
  */
582
742
  requestEntityTooLarge(body?: any, generateEtag?: boolean): void;
583
743
  /**
584
- * Shorthand method to finish request with "414" status code
744
+ * Sends a 414 URI Too Long response
745
+ *
746
+ * @param body - Response body
747
+ * @param generateEtag - Whether to generate ETag header
585
748
  */
586
749
  requestUriTooLong(body?: any, generateEtag?: boolean): void;
587
750
  /**
588
- * Shorthand method to finish request with "415" status code
751
+ * Sends a 415 Unsupported Media Type response
752
+ *
753
+ * @param body - Response body
754
+ * @param generateEtag - Whether to generate ETag header
589
755
  */
590
756
  unsupportedMediaType(body?: any, generateEtag?: boolean): void;
591
757
  /**
592
- * Shorthand method to finish request with "416" status code
758
+ * Sends a 416 Range Not Satisfiable response
759
+ *
760
+ * @param body - Response body
761
+ * @param generateEtag - Whether to generate ETag header
593
762
  */
594
763
  requestedRangeNotSatisfiable(body?: any, generateEtag?: boolean): void;
595
764
  /**
596
- * Shorthand method to finish request with "417" status code
765
+ * Sends a 417 Expectation Failed response
766
+ *
767
+ * @param body - Response body
768
+ * @param generateEtag - Whether to generate ETag header
597
769
  */
598
770
  expectationFailed(body?: any, generateEtag?: boolean): void;
599
771
  /**
600
- * Shorthand method to finish request with "422" status code
772
+ * Sends a 422 Unprocessable Entity response
773
+ *
774
+ * @param body - Response body
775
+ * @param generateEtag - Whether to generate ETag header
601
776
  */
602
777
  unprocessableEntity(body?: any, generateEtag?: boolean): void;
603
778
  /**
604
- * Shorthand method to finish request with "429" status code
779
+ * Sends a 429 Too Many Requests response
780
+ *
781
+ * @param body - Response body
782
+ * @param generateEtag - Whether to generate ETag header
605
783
  */
606
784
  tooManyRequests(body?: any, generateEtag?: boolean): void;
607
785
  /**
608
- * Shorthand method to finish request with "500" status code
786
+ * Sends a 500 Internal Server Error response
787
+ *
788
+ * @param body - Response body
789
+ * @param generateEtag - Whether to generate ETag header
609
790
  */
610
791
  internalServerError(body?: any, generateEtag?: boolean): void;
611
792
  /**
612
- * Shorthand method to finish request with "501" status code
793
+ * Sends a 501 Not Implemented response
794
+ *
795
+ * @param body - Response body
796
+ * @param generateEtag - Whether to generate ETag header
613
797
  */
614
798
  notImplemented(body?: any, generateEtag?: boolean): void;
615
799
  /**
616
- * Shorthand method to finish request with "502" status code
800
+ * Sends a 502 Bad Gateway response
801
+ *
802
+ * @param body - Response body
803
+ * @param generateEtag - Whether to generate ETag header
617
804
  */
618
805
  badGateway(body?: any, generateEtag?: boolean): void;
619
806
  /**
620
- * Shorthand method to finish request with "503" status code
807
+ * Sends a 503 Service Unavailable response
808
+ *
809
+ * @param body - Response body
810
+ * @param generateEtag - Whether to generate ETag header
621
811
  */
622
812
  serviceUnavailable(body?: any, generateEtag?: boolean): void;
623
813
  /**
624
- * Shorthand method to finish request with "504" status code
814
+ * Sends a 504 Gateway Timeout response
815
+ *
816
+ * @param body - Response body
817
+ * @param generateEtag - Whether to generate ETag header
625
818
  */
626
819
  gatewayTimeout(body?: any, generateEtag?: boolean): void;
627
820
  /**
628
- * Shorthand method to finish request with "505" status code
821
+ * Sends a 505 HTTP Version Not Supported response
822
+ *
823
+ * @param body - Response body
824
+ * @param generateEtag - Whether to generate ETag header
629
825
  */
630
826
  httpVersionNotSupported(body?: any, generateEtag?: boolean): void;
631
827
  }