Skip to content

CORSMiddleware_Configuration

Josh Wright edited this page Jan 14, 2021 · 3 revisions

CORSMiddleware.Configuration

Configuration used for populating headers in response for CORS requests.

public struct Configuration

Initializers

init(allowedOrigin:allowedMethods:allowedHeaders:allowCredentials:cacheExpiration:exposedHeaders:)

Instantiate a CORSConfiguration struct that can be used to create a CORSConfiguration middleware for adding support for CORS in your responses.

public init(allowedOrigin: AllowOriginSetting, allowedMethods: [HTTPMethod], allowedHeaders: [String], allowCredentials: Bool = false, cacheExpiration: Int? = 600, exposedHeaders: [String]? = nil)

Parameters

  • allowedOrigin: Setting that controls which origin values are allowed.
  • allowedMethods: Methods that are allowed for a CORS request response.
  • allowedHeaders: Headers that are allowed in a response for CORS request.
  • allowCredentials: If cookies and other credentials will be sent in the response.
  • cacheExpiration: Optionally sets expiration of the cached pre-flight request in seconds.
  • exposedHeaders: Headers exposed in the response of pre-flight request.

Properties

allowedOrigin

Setting that controls which origin values are allowed.

let allowedOrigin: AllowOriginSetting

allowedMethods

Header string containing methods that are allowed for a CORS request response.

let allowedMethods: String

allowedHeaders

Header string containing headers that are allowed in a response for CORS request.

let allowedHeaders: String

allowCredentials

If set to yes, cookies and other credentials will be sent in the response for CORS request.

let allowCredentials: Bool

cacheExpiration

Optionally sets expiration of the cached pre-flight request. Value is in seconds.

let cacheExpiration: Int?

exposedHeaders

Headers exposed in the response of pre-flight request.

let exposedHeaders: String?

Methods

`default`()

Default CORS configuration.

public static func `default`() -> Configuration
  • Allow Origin: Based on request's Origin value.

  • Allow Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH

  • Allow Headers: Accept, Authorization, Content-Type, Origin, X-Requested-With

Alchemy
Types
Protocols
Global Typealiases
Global Variables
Global Functions
Fusion
Types
Protocols
Papyrus
Types
Protocols
Clone this wiki locally