{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Network.Wai.Routing.Purescheme.Core.Method
( method
)
where
import Network.Wai.Routing.Purescheme.Core.Basic
import Network.Wai.Routing.Purescheme.Core.Internal
import qualified Data.Text.Encoding as T
import Network.HTTP.Types (StdMethod, renderStdMethod, methodNotAllowed405, statusMessage)
import Network.Wai (requestMethod)
method :: StdMethod -> GenericApplication e -> GenericApplication e
method :: StdMethod -> GenericApplication e -> GenericApplication e
method StdMethod
m GenericApplication e
f Request
req =
if Request -> Method
requestMethod Request
req Method -> Method -> Bool
forall a. Eq a => a -> a -> Bool
== StdMethod -> Method
renderStdMethod StdMethod
m
then GenericApplication e
f Request
req
else Rejection -> (e -> IO ResponseReceived) -> IO ResponseReceived
forall r.
Rejection -> (r -> IO ResponseReceived) -> IO ResponseReceived
reject Rejection
methodNotAllowedRejection
methodNotAllowedRejection :: Rejection
methodNotAllowedRejection :: Rejection
methodNotAllowedRejection =
Rejection :: Text -> Int -> Status -> ResponseHeaders -> Rejection
Rejection
{ status :: Status
status = Status
methodNotAllowed405
, message :: Text
message = Method -> Text
T.decodeUtf8 (Method -> Text) -> Method -> Text
forall a b. (a -> b) -> a -> b
$ Status -> Method
statusMessage Status
methodNotAllowed405
, priority :: Int
priority = Int
100
, headers :: ResponseHeaders
headers = []
}