wai-utilities-0.16.1: Various helpers for WAI
Safe HaskellSafe-Inferred
LanguageGHC2021

Network.Wai.Utilities.Server

Synopsis

Server Setup

compile :: Monad m => Routes a m b -> Tree (App m) Source #

Middlewares

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

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.

Constants