module Network.Wai.Middleware.Timeout
( timeout
, timeoutStatus
, timeoutAs
) where
import Network.HTTP.Types (Status, status503)
import Network.Wai
import qualified System.Timeout as Timeout
timeout :: Int -> Middleware
timeout :: Int -> Middleware
timeout = Status -> Int -> Middleware
timeoutStatus Status
status503
timeoutStatus :: Status -> Int -> Middleware
timeoutStatus :: Status -> Int -> Middleware
timeoutStatus Status
status = Response -> Int -> Middleware
timeoutAs forall a b. (a -> b) -> a -> b
$ Status -> ResponseHeaders -> ByteString -> Response
responseLBS Status
status [] ByteString
""
timeoutAs :: Response -> Int -> Middleware
timeoutAs :: Response -> Int -> Middleware
timeoutAs Response
timeoutReponse Int
seconds Application
app Request
req Response -> IO ResponseReceived
respond =
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Response -> IO ResponseReceived
respond Response
timeoutReponse) forall (f :: * -> *) a. Applicative f => a -> f a
pure
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. Int -> IO a -> IO (Maybe a)
Timeout.timeout (Int
seconds forall a. Num a => a -> a -> a
* Int
1000000) (Application
app Request
req Response -> IO ResponseReceived
respond)