module Airbrake.WebRequest (
WebRequest (..)
) where
import Data.ByteString.UTF8 (toString)
import Data.Maybe
import qualified Network.Wai as Wai
import Network.URI
class WebRequest a where
url :: a -> URI
route :: a -> Maybe String
action :: a -> Maybe String
otherVars :: a -> [(String, String)]
instance WebRequest Wai.Request where
url req = case parseURI uriS of
Just u -> u
Nothing -> error "Failure producing URI from wai request."
where
uriS = (if Wai.isSecure req then "https://" else "http://")
++ show (Wai.remoteHost req)
++ toString (Wai.rawPathInfo req)
++ toString (Wai.rawQueryString req)
route _ = Nothing
action _ = Nothing
otherVars req = catMaybes
[ k "Host" "HTTP_HOST"
, k "User-Agent" "HTTP_USER_AGENT"
, k "Referer" "HTTP_REFERER"
, k "Cookie" "HTTP_COOKIE"
, if Wai.isSecure req then Just ("HTTPS", "on") else Nothing]
where k hdr key = fmap (\ v -> (key, toString v))
(lookup hdr (Wai.requestHeaders req))