Configuration

public struct Configuration

Configuration used for populating headers in response for CORS requests.

  • 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

    Declaration

    Swift

    public static func `default`() -> Configuration
  • Setting that controls which origin values are allowed.

    Declaration

    Swift

    public let allowedOrigin: AllowOriginSetting
  • Header string containing methods that are allowed for a CORS request response.

    Declaration

    Swift

    public let allowedMethods: String
  • Header string containing headers that are allowed in a response for CORS request.

    Declaration

    Swift

    public let allowedHeaders: String
  • If set to yes, cookies and other credentials will be sent in the response for CORS request.

    Declaration

    Swift

    public let allowCredentials: Bool
  • Optionally sets expiration of the cached pre-flight request. Value is in seconds.

    Declaration

    Swift

    public let cacheExpiration: Int?
  • Headers exposed in the response of pre-flight request.

    Declaration

    Swift

    public let exposedHeaders: String?
  • Instantiate a CORSConfiguration struct that can be used to create a CORSConfiguration middleware for adding support for CORS in your responses.

    Declaration

    Swift

    public init(
        allowedOrigin: AllowOriginSetting,
        allowedMethods: [HTTPMethod],
        allowedHeaders: [HTTPHeaderName],
        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.