-http_get uri = withCurlDo $ do
- resp <- curlGetString uri [CurlTimeout 45]
-
- case resp of
- (CurlOK, body) -> return (Just body)
- (code, _) -> do
- hPutStrLn stderr ("HTTP Error: " ++ (show code))
- return Nothing
+http_get uri =
+ withCurlDo $ do
+ -- Create a Curl instance.
+ curl <- initialize
+
+ -- Perform the request, and get back a CurlResponse object.
+ -- The cast is needed to specify how we would like our headers
+ -- and body returned (Strings).
+ resp <- do_curl_ curl uri curl_options :: IO CurlResponse
+
+ -- Pull out the response code as a CurlCode.
+ let code = respCurlCode resp
+
+ case code of
+ CurlOK -> return $ Just (respBody resp)
+ error_code -> do
+ hPutStrLn stderr ("HTTP Error: " ++ (show error_code))
+ -- If an error occurred, we want to dump as much information as
+ -- possible. If this becomes a problem, we can use respGetInfo to
+ -- query the response object for more information
+ return Nothing