http-client 0.3.3.2 → 0.3.4
raw patch · 4 files changed
+39/−17 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Network.HTTP.Client: applyBasicProxyAuth :: ByteString -> ByteString -> Request -> Request
+ Network.HTTP.Client.Internal: applyBasicProxyAuth :: ByteString -> ByteString -> Request -> Request
Files
- Network/HTTP/Client.hs +1/−0
- Network/HTTP/Client/Request.hs +15/−1
- http-client.cabal +1/−1
- test/Network/HTTP/Client/RequestSpec.hs +22/−15
Network/HTTP/Client.hs view
@@ -89,6 +89,7 @@ , requestHeaders , requestBody , proxy+ , applyBasicProxyAuth , decompress , redirectCount , checkStatus
Network/HTTP/Client/Request.hs view
@@ -14,6 +14,7 @@ , alwaysDecompress , addProxy , applyBasicAuth+ , applyBasicProxyAuth , urlEncodedBody , needsGunzip , requestBuilder@@ -230,7 +231,6 @@ authHeader = (CI.mk "Authorization", basic) basic = S8.append "Basic " (B64.encode $ S8.concat [ user, ":", passwd ]) - -- | Add a proxy to the Request so that the Request when executed will use -- the provided proxy. --@@ -238,6 +238,20 @@ addProxy :: S.ByteString -> Int -> Request -> Request addProxy hst prt req = req { proxy = Just $ Proxy hst prt }++-- | Add a Proxy-Authorization header (with the specified username and+-- password) to the given 'Request'. Ignore error handling:+--+-- > applyBasicProxyAuth "user" "pass" <$> parseUrl "http://example.org"+--+-- Since 0.3.4++applyBasicProxyAuth :: S.ByteString -> S.ByteString -> Request -> Request+applyBasicProxyAuth user passwd req =+ req { requestHeaders = authHeader : requestHeaders req }+ where+ authHeader = (CI.mk "Proxy-Authorization", basic)+ basic = S8.append "Basic " (B64.encode $ S8.concat [ user , ":", passwd ]) -- | Add url-encoded parameters to the 'Request'. --
http-client.cabal view
@@ -1,5 +1,5 @@ name: http-client-version: 0.3.3.2+version: 0.3.4 synopsis: An HTTP client engine, intended as a base layer for more user-friendly packages. description: This codebase has been refactored from http-conduit. homepage: https://github.com/snoyberg/http-client
test/Network/HTTP/Client/RequestSpec.hs view
@@ -1,21 +1,28 @@ {-# LANGUAGE OverloadedStrings #-} module Network.HTTP.Client.RequestSpec where +import Control.Applicative ((<$>))+import Control.Monad (join)+import Data.Maybe (isJust) import Test.Hspec-import Network.HTTP.Client (parseUrl)+import Network.HTTP.Client (parseUrl, requestHeaders, applyBasicProxyAuth)+import Control.Monad (forM_) spec :: Spec-spec = describe "case insensitive scheme" $ do- let succeed s = it s $- case parseUrl s of- Nothing -> error "failed"- Just _ -> return () :: IO ()- failure s = it s $- case parseUrl s of- Nothing -> return () :: IO ()- Just req -> error $ show req- succeed "http://example.com"- succeed "httP://example.com"- succeed "HttP://example.com"- succeed "HttPs://example.com"- failure "ftp://example.com"+spec = do+ describe "case insensitive scheme" $ do+ forM_ ["http://example.com", "httP://example.com", "HttP://example.com", "HttPs://example.com"] $ \url ->+ it url $ case parseUrl url of+ Nothing -> error "failed"+ Just _ -> return () :: IO ()+ forM_ ["ftp://example.com"] $ \url ->+ it url $ case parseUrl url of+ Nothing -> return () :: IO ()+ Just req -> error $ show req+ describe "applyBasicProxyAuth" $ do+ let request = applyBasicProxyAuth "user" "pass" <$> parseUrl "http://example.org"+ field = join $ lookup "Proxy-Authorization" . requestHeaders <$> request+ it "Should add a proxy-authorization header" $ do+ field `shouldSatisfy` isJust+ it "Should add a proxy-authorization header with the specified username and password." $ do+ field `shouldBe` Just "Basic dXNlcjpwYXNz"