wai-cors 0.2.6 → 0.2.7
raw patch · 6 files changed
+51/−170 lines, 6 filesdep −resourcetdep −transformers-compatdep ~basedep ~base-unicode-symbolsdep ~filepathPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: resourcet, transformers-compat
Dependency ranges changed: base, base-unicode-symbols, filepath, mtl, tasty, transformers, wai, wai-websockets, websockets
API changes (from Hackage documentation)
- Network.Wai.Middleware.Cors: CorsResourcePolicy :: !(Maybe ([Origin], Bool)) -> ![Method] -> ![HeaderName] -> !(Maybe [HeaderName]) -> !(Maybe Int) -> !Bool -> !Bool -> !Bool -> CorsResourcePolicy
+ Network.Wai.Middleware.Cors: CorsResourcePolicy :: !Maybe ([Origin], Bool) -> ![Method] -> ![HeaderName] -> !Maybe [HeaderName] -> !Maybe Int -> !Bool -> !Bool -> !Bool -> CorsResourcePolicy
- Network.Wai.Middleware.Cors: [corsExposedHeaders] :: CorsResourcePolicy -> !(Maybe [HeaderName])
+ Network.Wai.Middleware.Cors: [corsExposedHeaders] :: CorsResourcePolicy -> !Maybe [HeaderName]
- Network.Wai.Middleware.Cors: [corsMaxAge] :: CorsResourcePolicy -> !(Maybe Int)
+ Network.Wai.Middleware.Cors: [corsMaxAge] :: CorsResourcePolicy -> !Maybe Int
- Network.Wai.Middleware.Cors: [corsOrigins] :: CorsResourcePolicy -> !(Maybe ([Origin], Bool))
+ Network.Wai.Middleware.Cors: [corsOrigins] :: CorsResourcePolicy -> !Maybe ([Origin], Bool)
Files
- CHANGELOG.md +6/−0
- LICENSE +1/−1
- src/Network/Wai/Middleware/Cors.hs +9/−66
- test/Server.hs +2/−13
- test/UnitTests.hs +1/−11
- wai-cors.cabal +32/−79
CHANGELOG.md view
@@ -1,3 +1,9 @@+0.2.7 (2019-06-06)+==================++* Remove support for `wai<3` and older versions of GHC from the code base.+* Fix a documentation bug [#23](https://github.com/larskuhtz/wai-cors/issues/23).+ 0.2.6 (2017-12-01) ==================
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015 Lars Kuhtz <lakuhtz@gmail.com>+Copyright (c) 2015-2019 Lars Kuhtz <lakuhtz@gmail.com> Copyright (c) 2014 AlephCloud Systems, Inc. Permission is hereby granted, free of charge, to any person obtaining
src/Network/Wai/Middleware/Cors.hs view
@@ -1,17 +1,15 @@-{-# LANGUAGE UnicodeSyntax #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE RecordWildCards #-}-{-# LANGUAGE LambdaCase #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternGuards #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE UnicodeSyntax #-} -- | -- Module: Network.Wai.Middleware.Cors -- Description: Cross-Origin resource sharing (CORS) for WAI -- Copyright:--- © 2015 Lars Kuhtz <lkuhtz@gmail.com,+-- © 2015-2019 Lars Kuhtz <lakuhtz@gmail.com, -- © 2014 AlephCloud Systems, Inc. -- License: MIT -- Maintainer: Lars Kuhtz <lakuhtz@gmail.com>@@ -81,22 +79,8 @@ , simpleMethods ) where -#ifndef MIN_VESION_base-#define MIN_VESION_base(x,y,z) 1-#endif--#ifndef MIN_VESION_wai-#define MIN_VESION_wai(x,y,z) 1-#endif--#if ! MIN_VERSION_base(4,8,0)-import Control.Applicative-#endif import Control.Monad.Error.Class import Control.Monad.Trans.Except-#if ! MIN_VERSION_wai(2,0,0)-import Control.Monad.Trans.Resource-#endif import qualified Data.Attoparsec.ByteString.Char8 as P import qualified Data.ByteString.Char8 as B8@@ -104,9 +88,6 @@ import qualified Data.CaseInsensitive as CI import Data.List (intersect, (\\), union) import Data.Maybe (catMaybes)-#if ! MIN_VERSION_base(4,8,0)-import Data.Monoid (mempty)-#endif import Data.Monoid.Unicode import Data.String @@ -115,14 +96,6 @@ import Prelude.Unicode -{--#if MIN_VERSION_wai(2,0,0)-type ReqMonad = IO-#else-type ReqMonad = ResourceT IO-#endif--}- -- | Origins are expected to be formated as described in -- <https://www.ietf.org/rfc/rfc6454.txt RFC6454> (section 6.2). -- In particular the string @*@ is not a valid origin (but the string@@ -140,7 +113,7 @@ -- response header. Note if you send @*@, credentials cannot be sent with the request. -- -- A value other than 'Nothing' is a tuple that consists of a list of- -- origins each with a Boolean flag that indicates if credentials are used+ -- origins and a Boolean flag that indicates if credentials are used -- to access the resource via CORS. -- -- Origins must be formated as described in@@ -315,17 +288,13 @@ cors ∷ (WAI.Request → Maybe CorsResourcePolicy) -- ^ A value of 'Nothing' indicates that the resource is not available for CORS → WAI.Middleware-#if MIN_VERSION_wai(3,0,0) cors policyPattern app r respond-#else-cors policyPattern app r-#endif -- We don't handle websockets, even if they include an @Origin@ header | isWebSocketsReq r = runApp | Just policy ← policyPattern r = case hdrOrigin of - -- No origin header: requect request+ -- No origin header: reject request Nothing → if corsRequireOrigin policy then res $ corsFailure "Origin header is missing" else runApp@@ -335,14 +304,8 @@ | otherwise = runApp where--#if MIN_VERSION_wai(3,0,0) res = respond runApp = app r respond-#else- res = return- runApp = app r-#endif -- Lookup the HTTP origin request header --@@ -379,11 +342,7 @@ Right headers → res $ WAI.responseLBS HTTP.ok200 (ch ⊕ headers) "" -- Actual CORS request-#if MIN_VERSION_wai(3,0,0) _ → addHeaders (ch ⊕ respCorsHeaders policy) app r respond-#else- _ → addHeaders (ch ⊕ respCorsHeaders policy) app r-#endif -- Compute HTTP response headers for a preflight request --@@ -454,7 +413,7 @@ -- -- This middleware does not check if the resource corresponds to the -- restrictions for simple requests. This is in accordance with--- <http://www.w3.org/TR/cors/>. It is the responsibility of the +-- <http://www.w3.org/TR/cors/>. It is the responsibility of the -- client (user-agent) to enforce CORS policy. The role of the server -- is to provide the client with the respective policy constraints. --@@ -548,28 +507,12 @@ -- | Add HTTP headers to a WAI response ---#if MIN_VERSION_wai(3,0,0) addHeaders ∷ HTTP.ResponseHeaders → WAI.Middleware addHeaders hdrs app req respond = app req $ \response → do let (st, headers, streamHandle) = WAI.responseToStream response streamHandle $ \streamBody → respond $ WAI.responseStream st (headers ⊕ hdrs) streamBody -#elif MIN_VERSION_wai(2,0,0)--addHeaders ∷ HTTP.ResponseHeaders → WAI.Middleware-addHeaders hdrs app req = do- (st, headers, src) ← WAI.responseToSource <$> app req- WAI.responseSource st (headers ⊕ hdrs) <$> src return--#else--addHeaders ∷ HTTP.ResponseHeaders → WAI.Middleware-addHeaders hdrs app req = do- (st, headers, src) ← WAI.responseSource <$> app req- return $ WAI.ResponseSource st (headers ⊕ hdrs) src-#endif- -- | Format a list of 'HTTP.HeaderName's such that it can be used as -- an HTTP header value --@@ -580,7 +523,7 @@ -- an HTTP header value -- hdrL ∷ [B8.ByteString] → B8.ByteString-hdrL l = B8.intercalate ", " l+hdrL = B8.intercalate ", " corsFailure ∷ B8.ByteString -- ^ body
test/Server.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -7,7 +6,7 @@ -- | -- Module: Server -- Description: Test HTTP server for wai-cors--- Copyright: © 2015 Lars Kuhtz <lakuhtz@gmail.com>.+-- Copyright: © 2015-2018 Lars Kuhtz <lakuhtz@gmail.com>. -- License: MIT -- Maintainer: Lars Kuhtz <lakuhtz@gmail.com> -- Stability: experimental@@ -16,10 +15,6 @@ ( main ) where -#ifndef MIN_VERSION_wai-#define MIN_VERSION_wai(a,b,c) 1-#endif- import Control.Concurrent import Control.Exception import Control.Monad@@ -46,15 +41,9 @@ "cors":_ → corsapp request _ → testapp where-#if MIN_VERSION_wai(2,0,0) testapp respond = respond $ WAI.responseFile HTTP.status200 [] "index.html" Nothing corsapp = WS.websocketsOr WS.defaultConnectionOptions wsserver $ \_ respond → respond $ WAI.responseLBS HTTP.status200 [] "Success"-#else- testapp = WAI.responseFile HTTP.status200 [] "index.html" Nothing- corsapp = WS.websocketsOr WS.defaultConnectionOptions wsserver $ \_ →- WAI.responseLBS HTTP.status200 [] "Success"-#endif -- -------------------------------------------------------------------------- -- -- CORS Policy@@ -96,7 +85,7 @@ -- Note that Chrome sends @Origin: null@ when loaded from a "file://..." URL, -- PhantomJS sends "file://". ---nonSimplePolicy :: CorsResourcePolicy+nonSimplePolicy ∷ CorsResourcePolicy nonSimplePolicy = CorsResourcePolicy { corsOrigins = Just (["http://localhost:8080", "null", "file://"], False) , corsMethods = ["PUT"]
test/UnitTests.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE CPP #-}-{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE UnicodeSyntax #-}@@ -7,7 +5,7 @@ -- | -- Module: UnitTests -- Description: Unit Tests for wai-cors--- Copyright: © 2015 Lars Kuhtz <lakuhtz@gmail.com>.+-- Copyright: © 2015-2018 Lars Kuhtz <lakuhtz@gmail.com>. -- License: MIT -- Maintainer: Lars Kuhtz <lakuhtz@gmail.com> -- Stability: experimental@@ -24,10 +22,6 @@ , head ) where -#ifndef MIN_VERSION_wai-#define MIN_VERSION_wai(a,b,c) 1-#endif- import Network.Wai.Middleware.Cors import qualified Network.HTTP.Types as HTTP import qualified Network.Wai as WAI@@ -146,9 +140,5 @@ options = corsRequest { WAI.requestMethod = "OPTIONS" } app ∷ WAI.Application-#if MIN_VERSION_wai(2,0,0) app _ respond = respond $ WAI.responseLBS HTTP.status200 [] "Success"-#else-app _ = WAI.responseLBS HTTP.status200 [] "Success"-#endif
wai-cors.cabal view
@@ -1,10 +1,10 @@ -- ------------------------------------------------------ ----- Copyright © 2015-2017 Lars Kuhtz <lakuhtz@gmail.com>+-- Copyright © 2015-2019 Lars Kuhtz <lakuhtz@gmail.com> -- Copyright © 2014 AlephCloud Systems, Inc. -- ------------------------------------------------------ -- Name: wai-cors-Version: 0.2.6+Version: 0.2.7 Synopsis: CORS for WAI Description:@@ -20,12 +20,17 @@ Author: Lars Kuhtz <lakuhtz@gmail.com> Maintainer: Lars Kuhtz <lakuhtz@gmail.com> Copyright:- (c) 2015-2017 Lars Kuhtz <lakuhtz@gmail.com>,+ (c) 2015-2019 Lars Kuhtz <lakuhtz@gmail.com>, (c) 2014 AlephCloud Systems, Inc.-Category: HTTP, Network, Web, Yesod+Category: HTTP, Network, Web, Wai Build-type: Simple-Cabal-version: >= 1.14.0-tested-with: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.1, GHC == 8.2.2+Cabal-version: 1.22+tested-with:+ GHC == 7.10.3+ GHC == 8.0.2+ GHC == 8.2.2+ GHC == 8.4.4+ GHC == 8.6.5 data-files: README.md@@ -44,22 +49,7 @@ source-repository this type: git location: https://github.com/larskuhtz/wai-cors- tag: 0.2.6--flag transformers-3- description: use transformers<0.3 (this is set automatically)- default: False- manual: False--flag wai-1- description: use version wai<2 (this is set automatically)- default: False- manual: False--flag wai-2- description: use version wai<3 (this is set automatically)- default: False- manual: False+ tag: 0.2.7 Library default-language: Haskell2010@@ -70,34 +60,14 @@ build-depends: attoparsec >= 0.10.4.0,- base == 4.*,+ base >= 4.8 && <5.0, base-unicode-symbols >= 0.2.2.3, bytestring >= 0.10.0.2, case-insensitive >= 1.0.0.1,- http-types >= 0.8.0-- if flag(wai-1) && !flag(wai-2)- build-depends:- wai < 2.0,- resourcet >= 0.4,- transformers < 0.4- if flag(wai-2)- build-depends:- wai < 3.0 && >= 2.0- if !flag(wai-1) && !flag(wai-2)- build-depends:- wai >= 3.0-- if flag(transformers-3)- build-depends:- mtl >= 2.1,- transformers >= 0.3 && < 0.4,- transformers-compat >= 0.3- else- build-depends:- mtl >= 2.2,- transformers >= 0.4,- wai >= 2+ http-types >= 0.8.0,+ mtl >= 2.2,+ transformers >= 0.4,+ wai >= 3.0 ghc-options: -Wall @@ -111,7 +81,7 @@ Server build-depends:- base == 4.*,+ base >= 4.8 && <5.0, base-unicode-symbols >= 0.2, directory >= 1.2, filepath >= 1.4,@@ -119,22 +89,11 @@ network >= 2.6, process >= 1.2, text >= 1.2,- wai-cors-- if impl(ghc < 7.8)- build-depends:- filepath < 1.4.1.2-- -- We only build the tests suite with the more recent versions of wai and ghc.- -- Cabal fails to resolves the old dependencies otherwise.- if flag (wai-1) || flag (wai-2) || impl(ghc < 7.10)- buildable: False- else- build-depends:- wai-websockets >= 3.0,- warp >= 3.0,- wai >= 3.0,- websockets >= 0.9+ wai >= 3.0,+ wai-cors,+ wai-websockets >= 3.0,+ warp >= 3.0,+ websockets >= 0.9 ghc-options: -threaded -Wall -with-rtsopts=-N @@ -145,24 +104,18 @@ hs-source-dirs: test build-depends:- base == 4.*,+ base >= 4.8 && <5.0, base-unicode-symbols >= 0.2,+ base-unicode-symbols >= 0.2, http-types >= 0.8,- tasty >= 0.10,+ tasty >= 0.11, tasty-hunit >= 0.9,- wai-cors-- -- We only build the tests suite with the more recent versions of wai and ghc.- -- Cabal fails to resolves the old dependencies otherwise.- if flag (wai-1) || flag (wai-2) || impl(ghc < 7.10)- buildable: False- else- build-depends:- wai-extra >= 3.0,- wai-websockets >= 3.0,- warp >= 3.0,- wai >= 3.0,- websockets >= 0.9+ wai >= 3.0,+ wai-cors,+ wai-extra >= 3.0,+ wai-websockets >= 3.0.1,+ warp >= 3.0,+ websockets >= 0.10 ghc-options: -threaded -Wall -with-rtsopts=-N