Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions library/Ratel/Wai.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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))
}
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down