@adonisjs/http-server 8.0.0-next.5 → 8.0.0-next.7

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-3XEJZ4S4.js} +1105 -566
  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 +21 -2
  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 +62 -9
  29. package/build/src/request.d.ts +109 -10
  30. package/build/src/response.d.ts +416 -203
  31. package/build/src/router/brisk.d.ts +13 -0
  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 +18 -1
  35. package/build/src/router/legacy/url_builder.d.ts +14 -14
  36. package/build/src/router/main.d.ts +73 -4
  37. package/build/src/router/matchers.d.ts +3 -0
  38. package/build/src/router/resource.d.ts +34 -1
  39. package/build/src/router/route.d.ts +9 -1
  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 +34 -9
  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 -19
  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 +24 -11
  56. package/package.json +17 -15
@@ -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
106
138
  *
107
- * Under the hood the callback is registered with
108
- * the "https://github.com/jshttp/on-finished" package
139
+ * The callback is executed when the response has been completely sent.
140
+ * Uses the "on-finished" package internally.
141
+ *
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,596 @@ 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
+ * Returns a Redirect instance for fluent API usage
462
+ *
463
+ * Use this overload when you want to use methods like `.toRoute()`, `.back()`,
464
+ * `.withQs()`, or other redirect builder methods.
465
+ *
466
+ * @returns Redirect instance for chaining redirect methods
410
467
  *
411
468
  * @example
412
- * ```js
413
- * response.redirect('/foo')
414
- * response.redirect().toRoute('foo.bar')
469
+ * ```ts
470
+ * response.redirect().toRoute('users.show', { id: 1 })
415
471
  * response.redirect().back()
472
+ * response.redirect().withQs().toPath('/dashboard')
416
473
  * ```
417
474
  */
418
475
  redirect(): Redirect;
476
+ /**
477
+ * Performs an immediate redirect to the specified path
478
+ *
479
+ * This overload directly redirects the request with the provided parameters.
480
+ * Use this when you have a simple redirect without needing the fluent API.
481
+ *
482
+ * @param path - The path or URL to redirect to (use 'back' for referrer redirect)
483
+ * @param forwardQueryString - Whether to forward current query string parameters
484
+ * @param statusCode - HTTP status code for redirect (defaults to 302 Found)
485
+ *
486
+ * @example
487
+ * ```ts
488
+ * response.redirect('/dashboard')
489
+ * response.redirect('/users', true, 301) // with query forwarding and 301 status
490
+ * response.redirect('back') // redirect to referrer
491
+ * ```
492
+ */
419
493
  redirect(path: string, forwardQueryString?: boolean, statusCode?: number): void;
420
494
  /**
421
- * Abort the request with custom body and a status code. 400 is
422
- * used when status is not defined
495
+ * Aborts the request with a custom response body and status code
496
+ *
497
+ * @param body - Response body for the aborted request
498
+ * @param status - HTTP status code (defaults to 400)
499
+ * @throws Always throws an HTTP exception
423
500
  */
424
501
  abort(body: any, status?: number): never;
425
502
  /**
426
- * Abort the request with custom body and a status code when
427
- * passed condition returns `true`
503
+ * Conditionally aborts the request if the condition is truthy
504
+ *
505
+ * @param condition - Condition to evaluate
506
+ * @param body - Response body for the aborted request
507
+ * @param status - HTTP status code (defaults to 400)
428
508
  */
429
509
  abortIf(condition: unknown, body: any, status?: number): asserts condition is undefined | null | false;
430
510
  /**
431
- * Abort the request with custom body and a status code when
432
- * passed condition returns `false`
511
+ * Conditionally aborts the request if the condition is falsy
512
+ *
513
+ * @param condition - Condition to evaluate
514
+ * @param body - Response body for the aborted request
515
+ * @param status - HTTP status code (defaults to 400)
433
516
  */
434
517
  abortUnless<T>(condition: T, body: any, status?: number): asserts condition is Exclude<T, undefined | null | false>;
435
518
  /**
436
- * Set signed cookie as the response header. The inline options overrides
437
- * all options from the config.
519
+ * Sets a signed cookie in the response
520
+ *
521
+ * @param key - Cookie name
522
+ * @param value - Cookie value
523
+ * @param options - Cookie options (overrides config defaults)
524
+ * @returns The Response instance for chaining
438
525
  */
439
526
  cookie(key: string, value: any, options?: Partial<CookieOptions>): this;
440
527
  /**
441
- * Set encrypted cookie as the response header. The inline options overrides
442
- * all options from the config.
528
+ * Sets an encrypted cookie in the response
529
+ *
530
+ * @param key - Cookie name
531
+ * @param value - Cookie value
532
+ * @param options - Cookie options (overrides config defaults)
533
+ * @returns The Response instance for chaining
443
534
  */
444
535
  encryptedCookie(key: string, value: any, options?: Partial<CookieOptions>): this;
445
536
  /**
446
- * Set unsigned cookie as the response header. The inline options overrides
447
- * all options from the config.
537
+ * Sets a plain (unsigned/unencrypted) cookie in the response
538
+ *
539
+ * @param key - Cookie name
540
+ * @param value - Cookie value
541
+ * @param options - Cookie options including encode flag
542
+ * @returns The Response instance for chaining
448
543
  */
449
544
  plainCookie(key: string, value: any, options?: Partial<CookieOptions & {
450
545
  encode: boolean;
451
546
  }>): this;
452
547
  /**
453
- * Clear existing cookie.
548
+ * Clears an existing cookie by setting it to expire
549
+ *
550
+ * @param key - Cookie name to clear
551
+ * @param options - Cookie options (should match original cookie options)
552
+ * @returns The Response instance for chaining
454
553
  */
455
554
  clearCookie(key: string, options?: Partial<CookieOptions>): this;
456
555
  /**
457
- * Finishes the response by writing the lazy body, when `explicitEnd = true`
458
- * and response is already pending.
556
+ * Finalizes and sends the response
459
557
  *
460
- * Calling this method twice or when `explicitEnd = false` is noop.
558
+ * Writes the buffered body (content, stream, or file) to the client.
559
+ * This method is idempotent - calling it multiple times has no effect.
461
560
  */
462
561
  finish(): void;
463
562
  /**
464
- * Shorthand method to finish request with "100" status code
563
+ * Sends a 100 Continue response
465
564
  */
466
565
  continue(): void;
467
566
  /**
468
- * Shorthand method to finish request with "101" status code
567
+ * Sends a 101 Switching Protocols response
469
568
  */
470
569
  switchingProtocols(): void;
471
570
  /**
472
- * Shorthand method to finish request with "200" status code
571
+ * Sends a 200 OK response
572
+ *
573
+ * @param body - Response body
574
+ * @param generateEtag - Whether to generate ETag header
473
575
  */
474
576
  ok(body: any, generateEtag?: boolean): void;
475
577
  /**
476
- * Shorthand method to finish request with "201" status code
578
+ * Sends a 201 Created response
579
+ *
580
+ * @param body - Response body
581
+ * @param generateEtag - Whether to generate ETag header
477
582
  */
478
583
  created(body?: any, generateEtag?: boolean): void;
479
584
  /**
480
- * Shorthand method to finish request with "202" status code
585
+ * Sends a 202 Accepted response
586
+ *
587
+ * @param body - Response body
588
+ * @param generateEtag - Whether to generate ETag header
481
589
  */
482
590
  accepted(body: any, generateEtag?: boolean): void;
483
591
  /**
484
- * Shorthand method to finish request with "203" status code
592
+ * Sends a 203 Non-Authoritative Information response
593
+ *
594
+ * @param body - Response body
595
+ * @param generateEtag - Whether to generate ETag header
485
596
  */
486
597
  nonAuthoritativeInformation(body: any, generateEtag?: boolean): void;
487
598
  /**
488
- * Shorthand method to finish request with "204" status code
599
+ * Sends a 204 No Content response
489
600
  */
490
601
  noContent(): void;
491
602
  /**
492
- * Shorthand method to finish request with "205" status code
603
+ * Sends a 205 Reset Content response
493
604
  */
494
605
  resetContent(): void;
495
606
  /**
496
- * Shorthand method to finish request with "206" status code
607
+ * Sends a 206 Partial Content response
608
+ *
609
+ * @param body - Response body
610
+ * @param generateEtag - Whether to generate ETag header
497
611
  */
498
612
  partialContent(body: any, generateEtag?: boolean): void;
499
613
  /**
500
- * Shorthand method to finish request with "300" status code
614
+ * Sends a 300 Multiple Choices response
615
+ *
616
+ * @param body - Response body
617
+ * @param generateEtag - Whether to generate ETag header
501
618
  */
502
619
  multipleChoices(body?: any, generateEtag?: boolean): void;
503
620
  /**
504
- * Shorthand method to finish request with "301" status code
621
+ * Sends a 301 Moved Permanently response
622
+ *
623
+ * @param body - Response body
624
+ * @param generateEtag - Whether to generate ETag header
505
625
  */
506
626
  movedPermanently(body?: any, generateEtag?: boolean): void;
507
627
  /**
508
- * Shorthand method to finish request with "302" status code
628
+ * Sends a 302 Found (Moved Temporarily) response
629
+ *
630
+ * @param body - Response body
631
+ * @param generateEtag - Whether to generate ETag header
509
632
  */
510
633
  movedTemporarily(body?: any, generateEtag?: boolean): void;
511
634
  /**
512
- * Shorthand method to finish request with "303" status code
635
+ * Sends a 303 See Other response
636
+ *
637
+ * @param body - Response body
638
+ * @param generateEtag - Whether to generate ETag header
513
639
  */
514
640
  seeOther(body?: any, generateEtag?: boolean): void;
515
641
  /**
516
- * Shorthand method to finish request with "304" status code
642
+ * Sends a 304 Not Modified response
643
+ *
644
+ * @param body - Response body
645
+ * @param generateEtag - Whether to generate ETag header
517
646
  */
518
647
  notModified(body?: any, generateEtag?: boolean): void;
519
648
  /**
520
- * Shorthand method to finish request with "305" status code
649
+ * Sends a 305 Use Proxy response
650
+ *
651
+ * @param body - Response body
652
+ * @param generateEtag - Whether to generate ETag header
521
653
  */
522
654
  useProxy(body?: any, generateEtag?: boolean): void;
523
655
  /**
524
- * Shorthand method to finish request with "307" status code
656
+ * Sends a 307 Temporary Redirect response
657
+ *
658
+ * @param body - Response body
659
+ * @param generateEtag - Whether to generate ETag header
525
660
  */
526
661
  temporaryRedirect(body?: any, generateEtag?: boolean): void;
527
662
  /**
528
- * Shorthand method to finish request with "400" status code
663
+ * Sends a 400 Bad Request response
664
+ *
665
+ * @param body - Response body
666
+ * @param generateEtag - Whether to generate ETag header
529
667
  */
530
668
  badRequest(body?: any, generateEtag?: boolean): void;
531
669
  /**
532
- * Shorthand method to finish request with "401" status code
670
+ * Sends a 401 Unauthorized response
671
+ *
672
+ * @param body - Response body
673
+ * @param generateEtag - Whether to generate ETag header
533
674
  */
534
675
  unauthorized(body?: any, generateEtag?: boolean): void;
535
676
  /**
536
- * Shorthand method to finish request with "402" status code
677
+ * Sends a 402 Payment Required response
678
+ *
679
+ * @param body - Response body
680
+ * @param generateEtag - Whether to generate ETag header
537
681
  */
538
682
  paymentRequired(body?: any, generateEtag?: boolean): void;
539
683
  /**
540
- * Shorthand method to finish request with "403" status code
684
+ * Sends a 403 Forbidden response
685
+ *
686
+ * @param body - Response body
687
+ * @param generateEtag - Whether to generate ETag header
541
688
  */
542
689
  forbidden(body?: any, generateEtag?: boolean): void;
543
690
  /**
544
- * Shorthand method to finish request with "404" status code
691
+ * Sends a 404 Not Found response
692
+ *
693
+ * @param body - Response body
694
+ * @param generateEtag - Whether to generate ETag header
545
695
  */
546
696
  notFound(body?: any, generateEtag?: boolean): void;
547
697
  /**
548
- * Shorthand method to finish request with "405" status code
698
+ * Sends a 405 Method Not Allowed response
699
+ *
700
+ * @param body - Response body
701
+ * @param generateEtag - Whether to generate ETag header
549
702
  */
550
703
  methodNotAllowed(body?: any, generateEtag?: boolean): void;
551
704
  /**
552
- * Shorthand method to finish request with "406" status code
705
+ * Sends a 406 Not Acceptable response
706
+ *
707
+ * @param body - Response body
708
+ * @param generateEtag - Whether to generate ETag header
553
709
  */
554
710
  notAcceptable(body?: any, generateEtag?: boolean): void;
555
711
  /**
556
- * Shorthand method to finish request with "407" status code
712
+ * Sends a 407 Proxy Authentication Required response
713
+ *
714
+ * @param body - Response body
715
+ * @param generateEtag - Whether to generate ETag header
557
716
  */
558
717
  proxyAuthenticationRequired(body?: any, generateEtag?: boolean): void;
559
718
  /**
560
- * Shorthand method to finish request with "408" status code
719
+ * Sends a 408 Request Timeout response
720
+ *
721
+ * @param body - Response body
722
+ * @param generateEtag - Whether to generate ETag header
561
723
  */
562
724
  requestTimeout(body?: any, generateEtag?: boolean): void;
563
725
  /**
564
- * Shorthand method to finish request with "409" status code
726
+ * Sends a 409 Conflict response
727
+ *
728
+ * @param body - Response body
729
+ * @param generateEtag - Whether to generate ETag header
565
730
  */
566
731
  conflict(body?: any, generateEtag?: boolean): void;
567
732
  /**
568
- * Shorthand method to finish request with "401" status code
733
+ * Sends a 410 Gone response
734
+ *
735
+ * @param body - Response body
736
+ * @param generateEtag - Whether to generate ETag header
569
737
  */
570
738
  gone(body?: any, generateEtag?: boolean): void;
571
739
  /**
572
- * Shorthand method to finish request with "411" status code
740
+ * Sends a 411 Length Required response
741
+ *
742
+ * @param body - Response body
743
+ * @param generateEtag - Whether to generate ETag header
573
744
  */
574
745
  lengthRequired(body?: any, generateEtag?: boolean): void;
575
746
  /**
576
- * Shorthand method to finish request with "412" status code
747
+ * Sends a 412 Precondition Failed response
748
+ *
749
+ * @param body - Response body
750
+ * @param generateEtag - Whether to generate ETag header
577
751
  */
578
752
  preconditionFailed(body?: any, generateEtag?: boolean): void;
579
753
  /**
580
- * Shorthand method to finish request with "413" status code
754
+ * Sends a 413 Payload Too Large response
755
+ *
756
+ * @param body - Response body
757
+ * @param generateEtag - Whether to generate ETag header
581
758
  */
582
759
  requestEntityTooLarge(body?: any, generateEtag?: boolean): void;
583
760
  /**
584
- * Shorthand method to finish request with "414" status code
761
+ * Sends a 414 URI Too Long response
762
+ *
763
+ * @param body - Response body
764
+ * @param generateEtag - Whether to generate ETag header
585
765
  */
586
766
  requestUriTooLong(body?: any, generateEtag?: boolean): void;
587
767
  /**
588
- * Shorthand method to finish request with "415" status code
768
+ * Sends a 415 Unsupported Media Type response
769
+ *
770
+ * @param body - Response body
771
+ * @param generateEtag - Whether to generate ETag header
589
772
  */
590
773
  unsupportedMediaType(body?: any, generateEtag?: boolean): void;
591
774
  /**
592
- * Shorthand method to finish request with "416" status code
775
+ * Sends a 416 Range Not Satisfiable response
776
+ *
777
+ * @param body - Response body
778
+ * @param generateEtag - Whether to generate ETag header
593
779
  */
594
780
  requestedRangeNotSatisfiable(body?: any, generateEtag?: boolean): void;
595
781
  /**
596
- * Shorthand method to finish request with "417" status code
782
+ * Sends a 417 Expectation Failed response
783
+ *
784
+ * @param body - Response body
785
+ * @param generateEtag - Whether to generate ETag header
597
786
  */
598
787
  expectationFailed(body?: any, generateEtag?: boolean): void;
599
788
  /**
600
- * Shorthand method to finish request with "422" status code
789
+ * Sends a 422 Unprocessable Entity response
790
+ *
791
+ * @param body - Response body
792
+ * @param generateEtag - Whether to generate ETag header
601
793
  */
602
794
  unprocessableEntity(body?: any, generateEtag?: boolean): void;
603
795
  /**
604
- * Shorthand method to finish request with "429" status code
796
+ * Sends a 429 Too Many Requests response
797
+ *
798
+ * @param body - Response body
799
+ * @param generateEtag - Whether to generate ETag header
605
800
  */
606
801
  tooManyRequests(body?: any, generateEtag?: boolean): void;
607
802
  /**
608
- * Shorthand method to finish request with "500" status code
803
+ * Sends a 500 Internal Server Error response
804
+ *
805
+ * @param body - Response body
806
+ * @param generateEtag - Whether to generate ETag header
609
807
  */
610
808
  internalServerError(body?: any, generateEtag?: boolean): void;
611
809
  /**
612
- * Shorthand method to finish request with "501" status code
810
+ * Sends a 501 Not Implemented response
811
+ *
812
+ * @param body - Response body
813
+ * @param generateEtag - Whether to generate ETag header
613
814
  */
614
815
  notImplemented(body?: any, generateEtag?: boolean): void;
615
816
  /**
616
- * Shorthand method to finish request with "502" status code
817
+ * Sends a 502 Bad Gateway response
818
+ *
819
+ * @param body - Response body
820
+ * @param generateEtag - Whether to generate ETag header
617
821
  */
618
822
  badGateway(body?: any, generateEtag?: boolean): void;
619
823
  /**
620
- * Shorthand method to finish request with "503" status code
824
+ * Sends a 503 Service Unavailable response
825
+ *
826
+ * @param body - Response body
827
+ * @param generateEtag - Whether to generate ETag header
621
828
  */
622
829
  serviceUnavailable(body?: any, generateEtag?: boolean): void;
623
830
  /**
624
- * Shorthand method to finish request with "504" status code
831
+ * Sends a 504 Gateway Timeout response
832
+ *
833
+ * @param body - Response body
834
+ * @param generateEtag - Whether to generate ETag header
625
835
  */
626
836
  gatewayTimeout(body?: any, generateEtag?: boolean): void;
627
837
  /**
628
- * Shorthand method to finish request with "505" status code
838
+ * Sends a 505 HTTP Version Not Supported response
839
+ *
840
+ * @param body - Response body
841
+ * @param generateEtag - Whether to generate ETag header
629
842
  */
630
843
  httpVersionNotSupported(body?: any, generateEtag?: boolean): void;
631
844
  }