APICORSConfig class

The CORS (Cross-Origin Resource Sharing) configuration of API responses.

Configured at cross_origin/api. See APICrossOriginConfig.

Constructors

APICORSConfig({Object? allowOrigin, Object? allowMethods, Object? allowHeaders, bool? allowCredentials, Object? exposeHeaders, int? maxAge, bool? varyOrigin})
APICORSConfig.fromJson(Map json)
factory
APICORSConfig.resolve({APIConfig? apiConfig, ArgsSimple? args})
Resolves from the cross_origin/api entry of apiConfig, overridden by the command-line options in args.
factory

Properties

allowCredentials bool
The Access-Control-Allow-Credentials value.
final
allowHeaders List<String>
The Access-Control-Allow-Headers value. Empty omits the header. See localhostAllowHeaders.
final
allowMethods List<String>
The Access-Control-Allow-Methods value. Empty omits the header.
final
allowOrigin List<String>
The allowed origins (Access-Control-Allow-Origin).
final
exposeHeaders List<String>
The Access-Control-Expose-Headers value. Empty omits the header.
final
hashCode int
The hash code for this object.
no setterinherited
maxAge int
The Access-Control-Max-Age value, in seconds, allowing the browser to cache a preflight and skip an OPTIONS round-trip per cross-origin call. Only sent on OPTIONS responses. Zero (the default) omits the header.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
varyOrigin bool
If true (the default) sends Vary: Origin.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolveAllowHeaders(String origin) List<String>
Resolves the Access-Control-Allow-Headers value for origin, appending localhostAllowHeaders for a localhost origin.
resolveAllowOrigin(String origin) String?
Resolves the Access-Control-Allow-Origin value for origin, or null when origin is not allowed and no header should be sent.
toJson() Map<String, dynamic>
toString() String
A string representation of this object.
override

Operators

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

Static Methods

isLocalhostOrigin(String origin) bool
Returns true if origin is a localhost origin.
normalizeOrigin(String origin) String
Normalizes an origin for comparison: lower-case and without a trailing / (added by APIServer.getOrigin when a request has no Origin header).
parseHeaderList(Object? value, List<String> def) List<String>
Parses a header list value, accepting a List or a comma separated String. Returns def for a null value, and an empty list for an explicitly empty value.
parseMaxAge(Object? value) int?
Parses a maxAge value, accepting an int or a String.

Constants

defaultAllowHeaders → const List<String>
The default value for allowHeaders.
defaultAllowMethods → const List<String>
The default value for allowMethods.
defaultExposeHeaders → const List<String>
The default value for exposeHeaders.
localhostAllowHeaders → const List<String>
Extra allowHeaders sent only to localhost origins: the Dart development server (webdev) sends an x-ijt header.