 import HTTP
+
+/// Error thrown during instantiation of the `CORSConfiguration`.
+public enum CORSConfigurationError: Error {
+
+    /// Configuration file could not be found.
+    case configurationFileNotFound
+
+    /// A required key is missing in the configuration file. The associated value is the key name.
+    case missingRequiredConfigurationKey(String)
+}
 
 /// Option for the allow origin header in responses for CORS requests.
 ///


    /// Uses custom string provided as an associated value.
    case custom(String)


    /// Creates the header string depending on the case of self.
    ///

    /// - Parameter config: The settings config dictionary that should be used to extract settings.
    /// - Throws: Node extraction errors, if extraction fails.
    public init(config: Settings.Config) throws {
        let cors: Node
        do {
            cors = try config.extract("cors") ?? config.extract("CORS")
        } catch {
            throw CORSConfigurationError.configurationFileNotFound
        }

        // Allowed origin
        do {
            let originString: String = try cors.extract("allowedOrigin")
            switch originString {
            case "all", "*": self.allowedOrigin = .all
            case "none", "": self.allowedOrigin = .none
            case "origin", "Origin": self.allowedOrigin = .originBased
            default: self.allowedOrigin = .custom(originString)
            }
        } catch {
            throw CORSConfigurationError.missingRequiredConfigurationKey("allowedOrigin")
        }

        // Get methods
        do {
            let methodArray: [String] = try cors.extract("allowedMethods")
            self.allowedMethods = methodArray.joined(separator: ", ").uppercased()
        } catch {
            throw CORSConfigurationError.missingRequiredConfigurationKey("allowedMethods")
        }

        // Get allowed headers
        do {
            let headersArray: [String] = try cors.extract("allowedHeaders")
            self.allowedHeaders = headersArray.joined(separator: ", ")
        } catch {
            throw CORSConfigurationError.missingRequiredConfigurationKey("allowedHeaders")
        }

        // Allow credentials
        let allowCredentials: Bool? = try cors.extract("allowCredentials")
