@@ -11,7 +11,8 @@ import qualified Data.ByteString.Char8 as S8
1111import Data.IP
1212import qualified Data.Text as T
1313import Data.Text (Text)
14−import Data.Text.Encoding (decodeUtf8)
14+import Data.Text.Encoding (decodeUtf8With)
15+import Data.Text.Encoding.Error (lenientDecode)
1516import Data.Time (NominalDiffTime)
1617import Data.Word (Word32)
1718import Network.HTTP.Types as H
@@ -32,10 +33,10 @@ formatAsJSON date req status responseSize duration reqBody response =
3233 , "size" .= responseSize
3334 , "body" .=
3435 if statusCode status >= 400
35− then Just . decodeUtf8 . toStrict . BB.toLazyByteString $ response
36+ then Just . decodeUtf8With lenientDecode . toStrict . BB.toLazyByteString $ response
3637 else Nothing
3738 ]
38− , "time" .= decodeUtf8 date
39+ , "time" .= decodeUtf8With lenientDecode date
3940 ]) <> "\n"
4041
4142word32ToHostAddress :: Word32 -> Text
@@ -47,12 +48,12 @@ readAsDouble = read
4748requestToJSON :: NominalDiffTime -> Request -> [S8.ByteString] -> Value
4849requestToJSON duration req reqBody =
4950 object
50− [ "method" .= decodeUtf8 (requestMethod req)
51− , "path" .= decodeUtf8 (rawPathInfo req)
51+ [ "method" .= decodeUtf8With lenientDecode (requestMethod req)
52+ , "path" .= decodeUtf8With lenientDecode (rawPathInfo req)
5253 , "queryString" .= map queryItemToJSON (queryString req)
5354 , "durationMs" .= (readAsDouble . printf "%.2f" . rationalToDouble $ toRational duration * 1000)
5455 , "size" .= requestBodyLengthToJSON (requestBodyLength req)
55− , "body" .= decodeUtf8 (S8.concat reqBody)
56+ , "body" .= decodeUtf8With lenientDecode (S8.concat reqBody)
5657 , "remoteHost" .= sockToJSON (remoteHost req)
5758 , "httpVersion" .= httpVersionToJSON (httpVersion req)
5859 , "headers" .= requestHeadersToJSON (requestHeaders req)
@@ -78,7 +79,7 @@ sockToJSON (SockAddrCan i) =
7879 object [ "can" .= i ]
7980
8081queryItemToJSON :: QueryItem -> Value
81−queryItemToJSON (name, mValue) = toJSON (decodeUtf8 name, fmap decodeUtf8 mValue)
82+queryItemToJSON (name, mValue) = toJSON (decodeUtf8With lenientDecode name, fmap (decodeUtf8With lenientDecode) mValue)
8283
8384requestHeadersToJSON :: RequestHeaders -> Value
8485requestHeadersToJSON = toJSON . map hToJ where
@@ -87,7 +88,7 @@ requestHeadersToJSON = toJSON . map hToJ where
8788 hToJ hd = headerToJSON hd
8889
8990headerToJSON :: Header -> Value
90−headerToJSON (headerName, header) = toJSON (decodeUtf8 . original $ headerName, decodeUtf8 header)
91+headerToJSON (headerName, header) = toJSON (decodeUtf8With lenientDecode . original $ headerName, decodeUtf8With lenientDecode header)
9192
9293portToJSON :: PortNumber -> Value
9394portToJSON = toJSON . toInteger