Vapor Documentation Beta

Structure CORSMiddleware.​Configuration

public struct Configuration

Configuration used for populating headers in response for CORS requests.

Member Of

CORSMiddleware

Middleware that adds support for CORS settings in request responses. For configuration of this middleware please use the CORSMiddleware.Configuration object.

Initializers

init(allowed​Origin:​allowed​Methods:​allowed​Headers:​allow​Credentials:​cache​Expiration:​exposed​Headers:​)

@available(*, deprecated, message: "exposedHeaders parameter now accepts [HTTPHeaders.Name]") public init(allowedOrigin: CORSMiddleware.AllowOriginSetting, allowedMethods: [HTTPMethod], allowedHeaders: [HTTPHeaders.Name], allowCredentials: Bool = false, cacheExpiration: Int? = 600, exposedHeaders: [String])

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

Parameters

allowed​Origin CORSMiddleware.​Allow​Origin​Setting

Setting that controls which origin values are allowed.

allowed​Methods [HTTPMethod]

Methods that are allowed for a CORS request response.

allowed​Headers [HTTPHeaders.​Name]

Headers that are allowed in a response for CORS request.

allow​Credentials Bool

If cookies and other credentials will be sent in the response.

cache​Expiration Int?

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

exposed​Headers [String]

Headers exposed in the response of pre-flight request.

init(allowed​Origin:​allowed​Methods:​allowed​Headers:​allow​Credentials:​cache​Expiration:​exposed​Headers:​)

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

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

Parameters

allowed​Origin Allow​Origin​Setting

Setting that controls which origin values are allowed.

allowed​Methods [HTTPMethod]

Methods that are allowed for a CORS request response.

allowed​Headers [HTTPHeaders.​Name]

Headers that are allowed in a response for CORS request.

allow​Credentials Bool

If cookies and other credentials will be sent in the response.

cache​Expiration Int?

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

exposed​Headers [HTTPHeaders.​Name]?

Headers exposed in the response of pre-flight request.

Properties

allowed​Origin

let allowedOrigin: AllowOriginSetting

Setting that controls which origin values are allowed.

allowed​Methods

let allowedMethods: String

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

allowed​Headers

let allowedHeaders: String

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

allow​Credentials

let allowCredentials: Bool

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

cache​Expiration

let cacheExpiration: Int?

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

exposed​Headers

let exposedHeaders: String?

Headers exposed in the response of pre-flight request.

Methods

`default`()

public static func `default`() -> Configuration

Default CORS 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