packages feed

http-dispatch 0.2.0.0 → 0.3.0.0

raw patch · 5 files changed

+25/−19 lines, 5 files

Files

http-dispatch.cabal view
@@ -1,5 +1,5 @@ name:                http-dispatch-version:             0.2.0.0+version:             0.3.0.0 synopsis:            High level HTTP client for Haskell description:         Please see README.md homepage:            http://github.com/owainlewis/http-dispatch#readme@@ -15,7 +15,6 @@ library   hs-source-dirs:      src   exposed-modules:     Network.HTTP.Dispatch.Core-                     , Network.HTTP.Dispatch.Headers                      , Network.HTTP.Dispatch.Types                      , Network.HTTP.Dispatch.Request   build-depends:       base >= 4.7 && < 5
src/Network/HTTP/Dispatch/Core.hs view
@@ -2,6 +2,7 @@ module Network.HTTP.Dispatch.Core        ( HTTPRequest(..)        , HTTPResponse(..)+       , HTTPRequestMethod(..)        , runRequest        , get        , post
− src/Network/HTTP/Dispatch/Headers.hs
@@ -1,7 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-module Network.HTTP.Dispatch.Headers where--import           Network.HTTP.Dispatch.Types (Header (..))--contentJSON :: Header-contentJSON = ("Content-Type", "application/json")
src/Network/HTTP/Dispatch/Request.hs view
@@ -2,13 +2,15 @@ module Network.HTTP.Dispatch.Request   ( toRequest   , runRequest+  , compileParams+  , withQueryParams   ) where -import qualified Control.Exception           as E import qualified Data.ByteString.Char8       as C import qualified Data.ByteString.Lazy        as LBS import qualified Data.CaseInsensitive        as CI import           Data.List                   (isPrefixOf)+import           Data.List                   (intersperse) import           Data.String                 (fromString) import           Network.HTTP.Client         as Client import           Network.HTTP.Client.TLS@@ -49,14 +51,23 @@                                     hv = C.unpack v in                                 (hk, hv)) rHdrs) rBody +compileParams :: [(String, String)] -> String+compileParams params = "?" ++ kweryParams+     where parts = map (\(k,v) -> mconcat [k, "=", v]) params+           kweryParams = mconcat $ Data.List.intersperse "&" parts++withQueryParams :: HTTPRequest -> [(String, String)] -> HTTPRequest+withQueryParams req params = req { reqUrl =+                                       let x = reqUrl req+                                           y = compileParams params+                                       in x ++ y+                                 }+ class Runnable a where   -- Run a HTTP request and return the response     runRequest :: a -> IO HTTPResponse     -- Run a HTTP request with custom settings (proxy, https etc) and return the response     runRequestWithSettings :: a -> ManagerSettings -> IO HTTPResponse--handleMyException :: HttpException -> IO HTTPResponse-handleMyException (StatusCodeException s hdrs cj) = return $ HTTPResponse (statusCode s) [] ""  instance Runnable HTTPRequest where     runRequest httpRequest = do
src/Network/HTTP/Dispatch/Types.hs view
@@ -31,7 +31,7 @@   , respBody    :: LBS.ByteString } deriving ( Eq, Show ) --- Helper methods+-- Update requests (additive) ---------------------------------------------------------------------------------------------  withHeader :: HTTPRequest -> Header -> HTTPRequest@@ -40,13 +40,15 @@ withHeaders :: HTTPRequest -> [Header] -> HTTPRequest withHeaders req headers = req { reqHeaders = headers } -dropHeaderWithKey :: HTTPRequest -> String -> HTTPRequest-dropHeaderWithKey req@(HTTPRequest _ _ hdrs _) headerKey =-  let filteredHeaders = filter (\(k,v) -> k /= headerKey) hdrs in-      withHeaders req filteredHeaders- withBody :: HTTPRequest -> LBS.ByteString -> HTTPRequest withBody req body = req { reqBody = pure body }  withMethod :: HTTPRequest -> HTTPRequestMethod -> HTTPRequest withMethod req method = req { reqMethod = method }++---------------------------------------------------------------------------------------------++dropHeaderWithKey :: HTTPRequest -> String -> HTTPRequest+dropHeaderWithKey req@(HTTPRequest _ _ hdrs _) headerKey =+  let filteredHeaders = filter (\(k,v) -> k /= headerKey) hdrs in+      withHeaders req filteredHeaders