{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
module Imm.HTTP.Simple (mkHandle, defaultManager, module Reexport) where
import Imm.HTTP
import Imm.Pretty
import Control.Exception.Safe
import Data.CaseInsensitive
import Network.Connection as Reexport
import Network.HTTP.Client as Reexport
import Network.HTTP.Client.TLS as Reexport
import URI.ByteString
mkHandle :: MonadBase IO m => Manager -> Handle m
mkHandle manager = Handle
{ httpGet = liftBase . httpGet' manager
}
defaultManager :: IO Manager
defaultManager = newManager $ mkManagerSettings (TLSSettingsSimple False False False) Nothing
httpGet' :: Manager -> URI -> IO LByteString
httpGet' manager uri = do
request <- makeRequest uri
responseBody <$> httpLbs request manager
parseRequest' :: MonadThrow m => URI -> m Request
parseRequest' = parseRequest . show . prettyURI
makeRequest :: URI -> IO Request
makeRequest uri = do
req <- parseRequest' uri
return $ req { requestHeaders = [
(mk "User-Agent", "Mozilla/4.0"),
(mk "Accept", "*/*")]}