on master help sign in
Add ‘basicProxyAuth’ authorization option
commit6c2c03e68156dbd9ca77e2206d85929961aa5460 authorRobert Soeldner <r.soeldner@gmail.com> dateMon 7 May 2018, 08:05 (8 years ago) parentafabf11
3 files changed+29
CHANGELOG.md+2 Network/HTTP/Req.hs+12 pure-tests/Network/HTTP/ReqSpec.hs+15
CHANGELOG.md+2
@@ -3,6 +3,8 @@
33* Added `customAuth` and `attachHeader` to facilitate creation of custom
44 authentication options.
55
6+* Added `basicProxyAuth` authentication option.
7+
68## Req 1.0.0
79
810* Added the `reqBr` function allowing to consume `Response BodyReader`
Network/HTTP/Req.hs+12
@@ -178,6 +178,7 @@ module Network.HTTP.Req
178178 -- $authentication
179179 , basicAuth
180180 , basicAuthUnsafe
181+ , basicProxyAuth
181182 , oAuth1
182183 , oAuth2Bearer
183184 , oAuth2Token
@@ -1284,6 +1285,17 @@ basicAuthUnsafe
12841285basicAuthUnsafe username password = customAuth
12851286 (pure . L.applyBasicAuth username password)
12861287
1288+-- | The 'Option' set basic proxy authentication header.
1289+--
1290+-- @since 1.1.0
1291+
1292+basicProxyAuth
1293+ :: ByteString -- ^ Username
1294+ -> ByteString -- ^ Password
1295+ -> Option scheme -- ^ Auth 'Option'
1296+basicProxyAuth username password =
1297+ withRequest (L.applyBasicProxyAuth username password)
1298+
12871299-- | The 'Option' adds OAuth1 authentication.
12881300--
12891301-- @since 0.2.0
pure-tests/Network/HTTP/ReqSpec.hs+15
@@ -37,6 +37,7 @@ import qualified Data.Text as T
3737import qualified Data.Text.Encoding as T
3838import qualified Network.HTTP.Client as L
3939import qualified Network.HTTP.Types as Y
40+import qualified Network.HTTP.Types.Header as Y
4041
4142spec :: Spec
4243spec = do
@@ -238,6 +239,12 @@ spec = do
238239 (oAuth2Bearer token0 <> oAuth2Bearer token1)
239240 lookup "Authorization" (L.requestHeaders request) `shouldBe`
240241 pure ("Bearer " <> token0)
242+ describe "ProxyAuthorization" $ do
243+ it "sets Authorization header to correct value" $
244+ property $ \username password -> do
245+ request <- req_ GET url NoReqBody (basicProxyAuth username password)
246+ lookup "Proxy-Authorization" (L.requestHeaders request) `shouldBe`
247+ pure (basicProxyAuthHeader username password)
241248 describe "oAuth2Token" $ do
242249 it "sets Authorization header to correct value" $
243250 property $ \token -> do
@@ -447,3 +454,11 @@ basicAuthHeader :: ByteString -> ByteString -> ByteString
447454basicAuthHeader username password =
448455 fromJust . lookup Y.hAuthorization . L.requestHeaders $
449456 L.applyBasicAuth username password L.defaultRequest
457+
458+-- | Get "Proxy-Authorization" basic proxy auth header given username and
459+-- password.
460+
461+basicProxyAuthHeader :: ByteString -> ByteString -> ByteString
462+basicProxyAuthHeader username password =
463+ fromJust . lookup Y.hProxyAuthorization . L.requestHeaders $
464+ L.applyBasicProxyAuth username password L.defaultRequest