Creates a new Response instance
Node.js IncomingMessage instance
Node.js ServerResponse instance
Encryption service for cookie handling
Response configuration settings
Router instance for URL generation
Query string parser
Lazy body container that holds response content until ready to send. Contains different types of response data: content, stream, or fileToStream.
Optional
ctxHTTP context reference (creates circular dependency with HttpContext)
Node.js IncomingMessage instance
Node.js ServerResponse instance
Indicates whether the response has any content (body, stream, or file) ready to be sent
Indicates whether the response has non-stream content set
Indicates whether the response body is set as a readable stream
Indicates whether the response is configured to stream a file
The response content data
The readable stream instance configured for the response
Configuration for file streaming including path and etag generation flag
Indicates whether the response has been completely sent
Indicates whether response headers have been sent to the client
Indicates whether the response is still pending (headers and body can still be modified)
Registers a callback to be called when the response is finished
The callback is executed when the response has been completely sent. Uses the "on-finished" package internally.
Function to call when response is finished
Transfers all buffered headers to the underlying Node.js response object
Writes the response status code and headers
Optional
statusCode: numberOptional status code to set
The Response instance for chaining
Gets the value of a response header
Header name
The header value
Gets all response headers as an object
Object containing all headers
Sets a response header (replaces existing value)
Header name
Header value (ignored if null/undefined)
The Response instance for chaining
Appends a value to an existing response header
Header name
Header value to append (ignored if null/undefined)
The Response instance for chaining
Sets a header only if it doesn't already exist
Header name
Header value
The Response instance for chaining
Removes a response header
Header name to remove
The Response instance for chaining
Gets the current response status code
The HTTP status code
Sets the response status code
HTTP status code
The Response instance for chaining
Sets the status code only if not explicitly set already
HTTP status code
The Response instance for chaining
Sets the Content-Type header based on mime type lookup
File extension or mime type
Optional
charset: stringOptional character encoding
The Response instance for chaining
Sets the Vary HTTP header for cache control
Header field name(s) to vary on
The Response instance for chaining
Sets the ETag header by computing a hash from the response body
The response body to hash
Whether to generate a weak ETag
The Response instance for chaining
Sets the X-Request-Id header by copying from the incoming request
The Response instance for chaining
Checks if the response is fresh (client cache is valid)
Compares ETags and modified dates between request and response to determine if a 304 Not Modified response should be sent.
True if client cache is fresh, false otherwise
Gets the response body content
The response body or null if not set or is a stream
Sends the response body with optional ETag generation
The response body
Whether to generate ETag header (defaults to config)
Sends a JSON response (alias for send)
The response body to serialize as JSON
Whether to generate ETag header
Sends a JSONP response with callback wrapping
Callback name resolution priority:
The response body
JSONP callback function name
Whether to generate ETag header
Pipes a readable stream to the response with graceful error handling
The readable stream to pipe
Optional
errorCallback: (error: ErrnoException) => [string, number?]Optional custom error handler
Downloads a file by streaming it with appropriate headers
Automatically sets:
Path to the file to download
Whether to generate ETag header
Optional
errorCallback: (error: ErrnoException) => [string, number?]Optional custom error handler
Forces file download by setting Content-Disposition header
Path to the file to download
Optional
name: stringOptional filename for download (defaults to original filename)
Optional
disposition: stringContent-Disposition type (defaults to 'attachment')
Optional
generateEtag: booleanWhether to generate ETag header
Optional
errorCallback: (error: ErrnoException) => [string, number?]Optional custom error handler
Returns a Redirect instance for fluent API usage
Use this overload when you want to use methods like .toRoute()
, .back()
,
.withQs()
, or other redirect builder methods.
Redirect instance for chaining redirect methods
Performs an immediate redirect to the specified path
This overload directly redirects the request with the provided parameters. Use this when you have a simple redirect without needing the fluent API.
The path or URL to redirect to (use 'back' for referrer redirect)
Optional
forwardQueryString: booleanWhether to forward current query string parameters
Optional
statusCode: numberHTTP status code for redirect (defaults to 302 Found)
Conditionally aborts the request if the condition is truthy
Condition to evaluate
Response body for the aborted request
Optional
status: numberHTTP status code (defaults to 400)
Sets a signed cookie in the response
Cookie name
Cookie value
Optional
options: Partial<CookieOptions>Cookie options (overrides config defaults)
The Response instance for chaining
Sets an encrypted cookie in the response
Cookie name
Cookie value
Optional
options: Partial<CookieOptions>Cookie options (overrides config defaults)
The Response instance for chaining
Sets a plain (unsigned/unencrypted) cookie in the response
Cookie name
Cookie value
Optional
options: Partial<CookieOptions & { encode: boolean }>Cookie options including encode flag
The Response instance for chaining
Clears an existing cookie by setting it to expire
Cookie name to clear
Optional
options: Partial<CookieOptions>Cookie options (should match original cookie options)
The Response instance for chaining
Finalizes and sends the response
Writes the buffered body (content, stream, or file) to the client. This method is idempotent - calling it multiple times has no effect.
Sends a 100 Continue response
Sends a 101 Switching Protocols response
Sends a 200 OK response
Response body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 201 Created response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 202 Accepted response
Response body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 203 Non-Authoritative Information response
Response body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 204 No Content response
Sends a 205 Reset Content response
Sends a 206 Partial Content response
Response body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 300 Multiple Choices response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 301 Moved Permanently response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 302 Found (Moved Temporarily) response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 303 See Other response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 304 Not Modified response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 305 Use Proxy response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 307 Temporary Redirect response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 400 Bad Request response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 401 Unauthorized response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 402 Payment Required response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 403 Forbidden response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 404 Not Found response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 405 Method Not Allowed response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 406 Not Acceptable response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 407 Proxy Authentication Required response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 408 Request Timeout response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 409 Conflict response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 410 Gone response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 411 Length Required response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 412 Precondition Failed response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 413 Payload Too Large response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 414 URI Too Long response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 415 Unsupported Media Type response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 416 Range Not Satisfiable response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 417 Expectation Failed response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 422 Unprocessable Entity response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 429 Too Many Requests response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 500 Internal Server Error response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 501 Not Implemented response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 502 Bad Gateway response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 503 Service Unavailable response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 504 Gateway Timeout response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
Sends a 505 HTTP Version Not Supported response
Optional
body: anyResponse body
Optional
generateEtag: booleanWhether to generate ETag header
The Response class provides a fluent API for constructing HTTP responses.
It wraps Node.js ServerResponse and streamlines the process of writing response body, setting headers, handling cookies, redirects, and streaming.
Example