ResponseHeaders class

Handles HTTP response headers with a clean, consistent API.

This class provides methods for setting, getting, and managing HTTP response headers with proper case-insensitive handling and convenient shortcuts for common headers.

Constructors

ResponseHeaders(HttpResponse _response)

Properties

contentLength int?
Gets the Content-Length header.
no setter
contentType ContentType?
Gets the Content-Type header.
no setter
hashCode int
The hash code for this object.
no setterinherited
raw HttpHeaders
Gets the raw HttpHeaders object for advanced operations.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addHeader(String name, String value) → void
Adds a response header (allows multiple values for the same header).
clearHeaders() → void
Clears all headers.
getFirstHeader(String name) String?
Gets the first value for a header.
getHeader(String name) List<String>?
Gets all values for a header.
hasHeader(String name) bool
Checks if a header exists.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeHeader(String name) → void
Removes a header.
setCacheControl(String value) → void
Sets the Cache-Control header.
setContentLength(int length) → void
Sets the Content-Length header.
setContentType(ContentType contentType) → void
Sets the Content-Type header.
setContentTypeString(String contentType) → void
Sets the Content-Type header from a string.
setCorsHeaders({String? allowOrigin, String? allowMethods, String? allowHeaders, String? exposeHeaders, bool allowCredentials = false, int? maxAge}) → void
Sets CORS headers.
setDate(DateTime date) → void
Sets the Date header.
setETag(String etag, {bool weak = false}) → void
Sets the ETag header.
setExpires(DateTime date) → void
Sets the Expires header.
setHeader(String name, String value) → void
Sets a response header.
setLastModified(DateTime date) → void
Sets the Last-Modified header.
setLocation(String location) → void
Sets the Location header.
setSecurityHeaders({bool enableHsts = false, bool enableCsp = false, bool enableXFrameOptions = true, bool enableXContentTypeOptions = true, String? cspPolicy}) → void
Sets common security headers.
setVary(String vary) → void
Sets the Vary header.
toString() String
A string representation of this object.
inherited

Operators

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