{-# 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 m f req =
if requestMethod req == renderStdMethod m
then f req
else reject methodNotAllowedRejection
methodNotAllowedRejection :: Rejection
methodNotAllowedRejection =
Rejection
{ status = methodNotAllowed405
, message = T.decodeUtf8 $ statusMessage methodNotAllowed405
, priority = 100
, headers = []
}