Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- data Server = Server {}
- defaultServer :: String -> Word16 -> Logger -> Server
- newSettings :: MonadIO m => Server -> m Settings
- runSettingsWithShutdown :: Settings -> Application -> Maybe Int -> IO ()
- runSettingsWithCleanup :: IO () -> Settings -> Application -> Maybe Int -> IO ()
- compile :: Monad m => Routes a m b -> Tree (App m)
- route :: MonadIO m => Tree (App m) -> Request -> Continue IO -> m ResponseReceived
- requestIdMiddleware :: Logger -> HeaderName -> Middleware
- catchErrors :: Logger -> HeaderName -> Middleware
- catchErrorsWithRequestId :: (Request -> Maybe ByteString) -> Logger -> Middleware
- heavyDebugLogging :: ((Request, LByteString) -> Maybe (Request, LByteString)) -> Level -> Logger -> HeaderName -> Middleware
- rethrow5xx :: (Request -> Maybe ByteString) -> Logger -> Middleware
- lazyResponseBody :: Response -> IO LByteString
- onError :: MonadIO m => Logger -> Maybe ByteString -> Request -> Continue IO -> Either Error JSONResponse -> m ResponseReceived
- logError :: MonadIO m => Logger -> Maybe Request -> Error -> m ()
- logError' :: MonadIO m => Logger -> Maybe ByteString -> Error -> m ()
- logErrorMsg :: Error -> Msg -> Msg
- flushRequestBody :: Request -> IO ()
- defaultRequestIdHeaderName :: HeaderName
- federationRequestIdHeaderName :: HeaderName
Server Setup
Server | |
|
runSettingsWithShutdown :: Settings -> Application -> Maybe Int -> IO () Source #
runSettingsWithCleanup :: IO () -> Settings -> Application -> Maybe Int -> IO () Source #
Middlewares
requestIdMiddleware :: Logger -> HeaderName -> Middleware Source #
catchErrors :: Logger -> HeaderName -> Middleware Source #
catchErrorsWithRequestId :: (Request -> Maybe ByteString) -> Logger -> Middleware Source #
Create a middleware that catches exceptions and turns
them into appropriate Error
responses, thereby logging
as well as counting server errors (i.e. exceptions that
yield 5xx responses).
This does not log any Response
values with error status.
See catchErrors
.
heavyDebugLogging :: ((Request, LByteString) -> Maybe (Request, LByteString)) -> Level -> Logger -> HeaderName -> Middleware Source #
If the log level is less sensitive than Debug
just call the underlying app unchanged.
Otherwise, pull a copy of the request body before running it, and if response status is >=
400
, log the entire request, including the body.
The request sanitizer is called on the Request
and its body before it is being logged,
giving you a chance to erase any confidential information.
WARNINGS:
- This may log confidential information if contained in the request. Use the sanitizer to avoid that.
- This does not catch any exceptions in the underlying app, so consider calling
catchErrors
before this. - Be careful with trying this in production: this puts a performance penalty on every
request (unless level is less sensitive than
Debug
).
rethrow5xx :: (Request -> Maybe ByteString) -> Logger -> Middleware Source #
Run the Application
; check the response status; if >=500, throw a Error
with
label "server-error"
and the body as the error message.
lazyResponseBody :: Response -> IO LByteString Source #
This flushes the response! If you want to keep using the response, you need to construct a new one with a fresh body stream.
Utilities
onError :: MonadIO m => Logger -> Maybe ByteString -> Request -> Continue IO -> Either Error JSONResponse -> m ResponseReceived Source #
Send an Error
response.
logError :: MonadIO m => Logger -> Maybe Request -> Error -> m () Source #
Log an Error
response for debugging purposes.
It would be nice to have access to the request body here, but that's already streamed away
by the handler in all likelyhood. See heavyDebugLogging
.
flushRequestBody :: Request -> IO () Source #