CorsMiddleware class base

Middleware that applies Cross-Origin Resource Sharing (CORS) headers to outgoing responses.

This middleware:

  • allows requests from any origin
  • permits GET, POST, PUT, DELETE, and OPTIONS methods
  • allows the Content-Type and Range request headers
  • exposes Content-Length and Content-Range response headers
  • short-circuits preflight OPTIONS requests

This type is intended for use in route or global middleware pipelines.

Example:

await CorsMiddleware.middleware(request, () async {
  request.response.write('OK');
});

Constructors

CorsMiddleware()

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 Methods

middleware(HttpRequest request, Future<void> next()) Future
Applies CORS headers to the response and handles preflight requests.