headersForRequest method Null safety

Map<String, dynamic> headersForRequest(
  1. Request request
)

Returns a map of HTTP headers for a request based on this policy.

This will add Access-Control-Allow-Origin, Access-Control-Expose-Headers and Access-Control-Allow-Credentials depending on the this policy.

Implementation

Map<String, dynamic> headersForRequest(Request request) {
  var origin = request.raw.headers.value("origin");

  var headers = <String, dynamic>{};
  headers["Access-Control-Allow-Origin"] = origin;

  if (exposedResponseHeaders.isNotEmpty) {
    headers["Access-Control-Expose-Headers"] =
        exposedResponseHeaders.join(", ");
  }

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

  return headers;
}