preflightResponse method Null safety

Response preflightResponse(
  1. Request req
)

Returns a preflight response for a given Request.

Contains the Access-Control-Allow-* headers for a CORS preflight request according to this policy. This method is invoked internally by Controllers that have a Controller.policy.

Implementation

Response preflightResponse(Request req) {
  final headers = {
    "Access-Control-Allow-Origin": req.raw.headers.value("origin"),
    "Access-Control-Allow-Methods": allowedMethods.join(", "),
    "Access-Control-Allow-Headers": allowedRequestHeaders.join(", ")
  };

  if (allowCredentials!) {
    headers["Access-Control-Allow-Credentials"] = "true";
  }

  if (cacheInSeconds != null) {
    headers["Access-Control-Max-Age"] = "$cacheInSeconds";
  }

  return Response.ok(null, headers: headers);
}