Supply response size to custom loggers when available.

This commit is contained in:
Yitz Gale 2019-06-24 16:09:53 +03:00
parent 8f9662b4a1
commit 913d584a7c
2 changed files with 5 additions and 5 deletions

View File

@ -118,8 +118,8 @@ apacheMiddleware ala app req sendResponse = app req $ \res -> do
customMiddleware :: Callback -> IO ZonedDate -> OutputFormatter -> Middleware
customMiddleware cb getdate formatter app req sendResponse = app req $ \res -> do
date <- liftIO getdate
-- We use Nothing for the response size since we generally don't know it
liftIO $ cb $ formatter date req (responseStatus res) Nothing
let msize = contentLength (responseHeaders res)
liftIO $ cb $ formatter date req (responseStatus res) msize
sendResponse res
customMiddlewareWithDetails :: Callback -> IO ZonedDate -> OutputFormatterWithDetails -> Middleware
@ -129,12 +129,12 @@ customMiddlewareWithDetails cb getdate formatter app req sendResponse = do
app req' $ \res -> do
t1 <- getCurrentTime
date <- liftIO getdate
-- We use Nothing for the response size since we generally don't know it
let msize = contentLength (responseHeaders res)
builderIO <- newIORef $ B.byteString ""
res' <- recordChunks builderIO res
rspRcv <- sendResponse res'
_ <- liftIO . cb .
formatter date req' (responseStatus res') Nothing (t1 `diffUTCTime` t0) reqBody =<<
formatter date req' (responseStatus res') msize (t1 `diffUTCTime` t0) reqBody =<<
readIORef builderIO
return rspRcv

View File

@ -1,5 +1,5 @@
Name: wai-extra
Version: 3.0.26
Version: 3.0.26.1
Synopsis: Provides some basic WAI handlers and middleware.
description:
Provides basic WAI handler and middleware functionality: