@@ -1,6 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22module Cors
33 ( allow
4+ , open
45 )
56 where
67
@@ -8,7 +9,7 @@ module Cors
89import qualified Data.HashSet as HashSet
910import Network.URI (parseURI)
1011import Snap.Core (Snap, Method, method)
11−import Snap.Util.CORS (CORSOptions(..), HashableMethod(..), OriginList(Origins), applyCORS, mkOriginSet)
12+import Snap.Util.CORS (CORSOptions(..), HashableMethod(..), OriginList(..), applyCORS, mkOriginSet)
1213
1314
1415
@@ -17,7 +18,15 @@ import Snap.Util.CORS (CORSOptions(..), HashableMethod(..), OriginList(Origins),
1718
1819allow :: Method -> [String] -> Snap () -> Snap ()
1920allow method_ origins snap =
20− applyCORS (toOptions method_ origins) $ method method_ $
21+ applyCORS (toOptions method_ (toOriginList origins)) $
22+ method method_ $
23+ snap
24+
25+
26+open :: Method -> Snap () -> Snap ()
27+open method_ snap =
28+ applyCORS (toOptions method_ Everywhere) $
29+ method method_ $
2130 snap
2231
2332
@@ -25,10 +34,9 @@ allow method_ origins snap =
2534-- TO OPTIONS
2635
2736
28−toOptions :: (Monad m) => Method -> [String] -> CORSOptions m
29−toOptions method_ origins =
37+toOptions :: (Monad m) => Method -> OriginList -> CORSOptions m
38+toOptions method_ allowedOrigins =
3039 let
31− allowedOrigins = toOriginList origins
3240 allowedMethods = HashSet.singleton (HashableMethod method_)
3341 in
3442 CORSOptions