@@ -49,15 +49,15 @@ setRQBody :: ByteString -> Req -> Req
49setRQBody b req = req { reqBody = b }
49setRQBody b req = req { reqBody = b }
51reqToRequest :: (Functor m, MonadThrow m) => Req -> BaseUrl -> m Request
51reqToRequest :: (Functor m, MonadThrow m) => Req -> BaseUrl -> m Request
52−reqToRequest req (BaseUrl scheme host port) = fmap (setrqb . setQS ) $ parseUrl url
52+reqToRequest req (BaseUrl reqScheme reqHost reqPort) = fmap (setrqb . setQS ) $ parseUrl url
54− where url = show $ nullURI { uriScheme = case scheme of
54+ where url = show $ nullURI { uriScheme = case reqScheme of
55 Http -> "http:"
55 Http -> "http:"
56 Https -> "https:"
56 Https -> "https:"
57 , uriAuthority = Just $
57 , uriAuthority = Just $
58 URIAuth { uriUserInfo = ""
58 URIAuth { uriUserInfo = ""
59− , uriRegName = host
59+ , uriRegName = reqHost
60− , uriPort = ":" ++ show port
60+ , uriPort = ":" ++ show reqPort
62 , uriPath = reqPath req
62 , uriPath = reqPath req
@@ -79,14 +79,14 @@ __withGlobalManager action = modifyMVar __manager $ \ manager -> do
81displayHttpRequest :: Method -> String
81displayHttpRequest :: Method -> String
82−displayHttpRequest method = "HTTP " ++ cs method ++ " request"
82+displayHttpRequest httpmethod = "HTTP " ++ cs httpmethod ++ " request"
85performRequest :: Method -> Req -> (Int -> Bool) -> BaseUrl -> EitherT String IO (Int, ByteString)
85performRequest :: Method -> Req -> (Int -> Bool) -> BaseUrl -> EitherT String IO (Int, ByteString)
86−performRequest method req isWantedStatus host = do
86+performRequest reqMethod req isWantedStatus reqHost = do
87− partialRequest <- liftIO $ reqToRequest req host
87+ partialRequest <- liftIO $ reqToRequest req reqHost
89− let request = partialRequest { Client.method = method
89+ let request = partialRequest { Client.method = reqMethod
90 , checkStatus = \ _status _headers _cookies -> Nothing
90 , checkStatus = \ _status _headers _cookies -> Nothing
@@ -95,12 +95,12 @@ performRequest method req isWantedStatus host = do
95 Client.httpLbs request manager
95 Client.httpLbs request manager
96 case eResponse of
96 case eResponse of
97 Left status ->
97 Left status ->
98− left (displayHttpRequest method ++ " failed with status: " ++ showStatus status)
98+ left (displayHttpRequest reqMethod ++ " failed with status: " ++ showStatus status)
100 Right response -> do
100 Right response -> do
101 let status = Client.responseStatus response
101 let status = Client.responseStatus response
102 unless (isWantedStatus (statusCode status)) $
102 unless (isWantedStatus (statusCode status)) $
103− left (displayHttpRequest method ++ " failed with status: " ++ showStatus status)
103+ left (displayHttpRequest reqMethod ++ " failed with status: " ++ showStatus status)
104 return $ (statusCode status, Client.responseBody response)
104 return $ (statusCode status, Client.responseBody response)
106 showStatus (Status code message) =
106 showStatus (Status code message) =
@@ -109,20 +109,20 @@ performRequest method req isWantedStatus host = do
110performRequestJSON :: FromJSON result =>
110performRequestJSON :: FromJSON result =>
111 Method -> Req -> Int -> BaseUrl -> EitherT String IO result
111 Method -> Req -> Int -> BaseUrl -> EitherT String IO result
112−performRequestJSON method req wantedStatus host = do
112+performRequestJSON reqMethod req wantedStatus reqHost = do
113− (_status, responseBody) <- performRequest method req (== wantedStatus) host
113+ (_status, respBody) <- performRequest reqMethod req (== wantedStatus) reqHost
115− (\ message -> left (displayHttpRequest method ++ " returned invalid json: " ++ message))
115+ (\ message -> left (displayHttpRequest reqMethod ++ " returned invalid json: " ++ message))
117− (decodeLenient responseBody)
117+ (decodeLenient respBody)
120catchStatusCodeException :: IO a -> IO (Either Status a)
120catchStatusCodeException :: IO a -> IO (Either Status a)
121−catchStatusCodeException action = catch (Right <$> action) $
121+catchStatusCodeException action =
122+ catch (Right <$> action) $ \e ->
122− \ e -> case e of
123+ case e of
123− Client.StatusCodeException status _ _ ->
124+ Client.StatusCodeException status _ _ -> return $ Left status
124− return $ Left status
125− e -> throwIO e
125+ exc -> throwIO exc
127-- | Like 'Data.Aeson.decode' but allows all JSON values instead of just
127-- | Like 'Data.Aeson.decode' but allows all JSON values instead of just
128-- objects and arrays.
128-- objects and arrays.