forked from vapor/vapor
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CORSMiddleware configuration initializer parameter (vapor#2314)
* Makes sure CORSMiddleware always adds before ErrorMiddleware * Deprecates the CORSMiddleware initializer which takes an [String] * Added the doc comment * Tanner's requested changes * Switched to a 'convenience' initializer
- Loading branch information
Showing
2 changed files
with
30 additions
and
3 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Sources/Vapor/Deprecations/CORSMiddleware+Configuration+exposedHeaders.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
extension CORSMiddleware.Configuration { | ||
/// Instantiate a CORSConfiguration struct that can be used to create a `CORSConfiguration` | ||
/// middleware for adding support for CORS in your responses. | ||
/// | ||
/// - 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. | ||
@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] | ||
) { | ||
let exposed = exposedHeaders.map { HTTPHeaders.Name($0) } | ||
self.init( | ||
allowedOrigin: allowedOrigin, allowedMethods: allowedMethods, allowedHeaders: allowedHeaders, | ||
allowCredentials: allowCredentials, cacheExpiration: cacheExpiration, exposedHeaders: exposed | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters