ResponseContext class

Provides access to the current HTTP response within a request processing zone.

This class enables services and controllers to access the current response without having to pass it as a parameter through the call chain.

Key features:

  • Zone-based response storage and retrieval
  • Response header management shortcuts
  • Content type helpers
  • Response timing and profiling

Constructors

ResponseContext()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

hasResponse bool
Check if a response context is currently available
no setter
isSent bool
Check if the response has been sent
no setter
response Response
Use this to access the current response in the zone.
no setter

Static Methods

cacheControl(String value) → void
Set Cache-Control header
contentTypeHtml() → void
Set Content-Type to HTML
contentTypeJson() → void
Set Content-Type to JSON
contentTypeText() → void
Set Content-Type to plain text
contentTypeXml() → void
Set Content-Type to XML
cors({String allowOrigin = '*', String allowMethods = 'GET, POST, PUT, DELETE, OPTIONS', String allowHeaders = 'Content-Type, Authorization'}) → void
Set CORS headers
Add a response header
html(String html) → void
Send an HTML response
json(Map<String, dynamic> data) → void
Send a JSON response
noCache() → void
Set no-cache headers
redirect(String url, {int status = 302}) Future<void>
Send a redirect response
status(int code) → void
Set the response status code
text(String text) → void
Send a plain text response