Safe Haskell | None |
---|
Add CORS (cross-origin resource sharing) headers to a Snap application. CORS headers can be added either conditionally or unconditionally to the entire site, or you can apply CORS headers to a single route.
- wrapCORS :: Initializer b v ()
- wrapCORSWithOptions :: CORSOptions (Handler b v) -> Initializer b v ()
- applyCORS :: MonadSnap m => CORSOptions m -> m ()
- data CORSOptions m = CORSOptions {}
- defaultOptions :: Monad m => CORSOptions m
- data OriginList
- = Everywhere
- | Nowhere
- | Origins OriginSet
- data OriginSet
- mkOriginSet :: [URI] -> OriginSet
- origins :: OriginSet -> HashSet HashableURI
- newtype HashableURI = HashableURI URI
Wrappers
wrapCORS :: Initializer b v ()Source
Apply CORS for every request, unconditionally.
wrapCors
≡ wrapCORSWithOptions
defaultOptions
wrapCORSWithOptions :: CORSOptions (Handler b v) -> Initializer b v ()Source
Initialize CORS for all requests with specific options.
Applying CORS to a specific response
applyCORS :: MonadSnap m => CORSOptions m -> m ()Source
Apply CORS headers to a specific request. This is useful if you only have a single action that needs CORS headers, and you don't want to pay for conditional checks on every request.
Option Specification
data CORSOptions m Source
Specify the options to use when building CORS headers for a response. Most
of these options are Handler
actions to allow you to conditionally
determine the setting of each header.
CORSOptions | |
|
defaultOptions :: Monad m => CORSOptions mSource
Liberal default options. Specifies that all origins may make cross-origin requests, allow-credentials is true. Headers are determined unconditionally.
Origin lists
data OriginList Source
Used to specify the contents of the Access-Control-Allow-Origin
header.
Everywhere | Allow any origin to access this resource. Corresponds to
|
Nowhere | Do not allow cross-origin requests |
Origins OriginSet | Allow cross-origin requests from these origins. |
mkOriginSet :: [URI] -> OriginSetSource
Internals
newtype HashableURI Source