on master help sign in
Using decodeUtf8' on Request Body

To prevent garbage data from polluting the logs, we check to see if the data can be safely be turned into utf8. If not, we ignore the line.

commit4d73e507852d7d0bd3d6e613c3caddd0f56efd3f authorNathan Smyth <nathan.andrew.smyth@gmail.com> dateThu 23 Jul 2015, 23:02 (11 years ago) parent364c0cd
1 file changed+3−1
wai-extra/Network/Wai/Middleware/RequestLogger.hs+3−1
wai-extra/Network/Wai/Middleware/RequestLogger.hs+3−1
@@ -44,6 +44,7 @@ import Network.Wai.Internal (Response (ResponseRaw))
4444import Data.Default.Class (Default (def))
4545import Network.Wai.Logger
4646import Network.Wai.Middleware.RequestLogger.Internal
47+import Data.Text.Encoding (decodeUtf8')
4748
4849data OutputFormat = Apache IPAddrSource
4950 | Detailed Bool -- ^ use colors?
@@ -222,7 +223,8 @@ detailedMiddleware' cb ansiColor ansiMethod ansiStatusCode app req sendResponse
222223 return (req', body)
223224 _ -> return (req, [])
224225
225− let reqbody = if null body then [""] else ansiColor White " Request Body: " <> body <> ["\n"]
226+ let reqbodylog _ = if null body then [""] else ansiColor White " Request Body: " <> body <> ["\n"]
227+ reqbody = concatMap (either (const [""]) reqbodylog . decodeUtf8') body
226228 postParams <- if requestMethod req `elem` ["GET", "HEAD"]
227229 then return []
228230 else do postParams <- liftIO $ allPostParams body