diff --git a/library/Ratel/Wai.hs b/library/Ratel/Wai.hs index b31408a..2bc0ce8 100644 --- a/library/Ratel/Wai.hs +++ b/library/Ratel/Wai.hs @@ -1,4 +1,4 @@ -module Ratel.Wai ( ratelMiddleware ) where +module Ratel.Wai ( ratelMiddleware, toRequest ) where import qualified Control.Concurrent as Concurrent import qualified Control.Exception as Exception @@ -19,20 +19,7 @@ ratelMiddleware apiKey maybeManager modify handle request respond = do respond response)) (\ exception -> do let err = Ratel.toError (exception :: Exception.SomeException) - let req = Ratel.Request - { Ratel.requestAction = Nothing - , Ratel.requestCgiData = Just (Map.union - (Map.fromList - [ ("REMOTE_ADDR", show (Wai.remoteHost request)) - , ("REQUEST_METHOD", BS.unpack (Wai.requestMethod request)) - ]) - (Map.fromList (map (\ (k, v) -> ("HTTP_" ++ map (\ c -> if c == '-' then '_' else Char.toUpper c) (BS.unpack (CI.foldedCase k)), BS.unpack v)) (Wai.requestHeaders request)))) - , Ratel.requestComponent = Nothing - , Ratel.requestContext = Nothing - , Ratel.requestParams = Just (Map.fromList (map (\ (k, v) -> (BS.unpack k, maybe "" BS.unpack v)) (Wai.queryString request))) - , Ratel.requestSession = Nothing - , Ratel.requestUrl = Just (BS.unpack (Wai.rawPathInfo request) ++ BS.unpack (Wai.rawQueryString request)) - } + let req = toRequest request let server = Ratel.Server { Ratel.serverEnvironmentName = Nothing , Ratel.serverHostname = Nothing @@ -48,3 +35,21 @@ ratelMiddleware apiKey maybeManager modify handle request respond = do _ <- Ratel.notify apiKey maybeManager payload return ()) Exception.throwIO exception) + + +toRequest :: Wai.Request -> Ratel.Request +toRequest request = + Ratel.Request + { Ratel.requestAction = Nothing + , Ratel.requestCgiData = Just (Map.union + (Map.fromList + [ ("REMOTE_ADDR", show (Wai.remoteHost request)) + , ("REQUEST_METHOD", BS.unpack (Wai.requestMethod request)) + ]) + (Map.fromList (map (\ (k, v) -> ("HTTP_" ++ map (\ c -> if c == '-' then '_' else Char.toUpper c) (BS.unpack (CI.foldedCase k)), BS.unpack v)) (Wai.requestHeaders request)))) + , Ratel.requestComponent = Nothing + , Ratel.requestContext = Nothing + , Ratel.requestParams = Just (Map.fromList (map (\ (k, v) -> (BS.unpack k, maybe "" BS.unpack v)) (Wai.queryString request))) + , Ratel.requestSession = Nothing + , Ratel.requestUrl = Just (BS.unpack (Wai.rawPathInfo request) ++ BS.unpack (Wai.rawQueryString request)) + } \ No newline at end of file diff --git a/package.yaml b/package.yaml index bf30026..c447606 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: ratel-wai -version: 1.0.5 +version: 1.0.6 category: Exceptions description: ratel-wai notifies Honeybadger about exceptions via a WAI middleware.