CtxResponse class

Response helper that tracks outgoing data and exposes the shared extras map used by middleware and handlers.

Constructors

CtxResponse(HttpRequest _request)
Creates a response helper bound to the provided HttpRequest.

Properties

bodyLength int?
Returns the length of the buffered response body, if any.
no setter
hashCode int
The hash code for this object.
no setterinherited
headers HttpHeaders
Mutable headers for the pending response.
no setter
isBodySuppressed bool
Whether the response body will be omitted when finalized.
no setter
isCommitted bool
Whether the underlying HttpResponse has already been written to.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
statusCode int
Status code that will be sent when the response is finalized.
no setter

Methods

badRequest([String message = "Bad Request"]) → void
Sends a 400 Bad Request response with an optional message.
bytes(List<int> bytes, {int status = HttpStatus.ok, ContentType? type}) → void
Sends a binary body optionally overriding status and content type.
conflict([String message = "Conflict"]) → void
Sends a 409 Conflict response with an optional message.
created(String location, {Object? jsonBody, String? textBody}) → void
201 Created with optional body and Location header. Provide either jsonBody or textBody, not both.
finalize() Future<void>
Flushes pending headers/body to the underlying HttpResponse.
forbidden([String message = "Forbidden"]) → void
Sends a 403 Forbidden response with an optional message.
found(String location) → void
Sends a 302 redirect to location.
gone([String message = "Gone"]) → void
Sends a 410 Gone response with an optional message.
html(String html, {int status = HttpStatus.ok, Encoding enc = utf8}) → void
Sends an HTML body encoded with enc.
internalServerError([String message = "Internal Server Error"]) → void
Sends a 500 Internal Server Error response with an optional message.
json(Object data, {int status = HttpStatus.ok}) → void
Serializes data as JSON and sends it with the provided status.
movedPermanently(String location) → void
Sends a 301 redirect to location.
noContent() → void
Sends a 204 response with no body.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notFound([String message = "Not Found"]) → void
Sends a 404 Not Found response with an optional message.
permanentRedirect(String location) → void
Sends a 308 redirect to location.
redirect(String location, {int status = HttpStatus.found}) → void
Generic redirect helper. Defaults to 302 Found.
seeOther(String location) → void
Sends a 303 redirect to location.
setCookie(Cookie cookie) → void
Adds a Cookie to the current HTTP response.
status(int code) → void
Updates the HTTP status code for the pending response.
stream(Stream<List<int>> source, {int status = HttpStatus.ok, ContentType? type, int? contentLength}) Future<void>
Streams an arbitrary byte source directly to the client.
string(String s, {int status = HttpStatus.ok, Encoding enc = utf8}) → void
Sends a plain-text body encoded with enc.
temporaryRedirect(String location) → void
Sends a 307 redirect to location.
toString() String
A string representation of this object.
inherited
unauthorized([String message = "Unauthorized"]) → void
Sends a 401 Unauthorized response with an optional message.

Operators

operator ==(Object other) bool
The equality operator.
inherited