on master help sign in
Add ‘basicProxyAuth’ authorization option
6c2c03eRobert Soeldner
CHANGELOG.md+2
@@ -3,6 +3,8 @@
3* Added `customAuth` and `attachHeader` to facilitate creation of custom
3* Added `customAuth` and `attachHeader` to facilitate creation of custom
4 authentication options.
4 authentication options.
5
5
6+* Added `basicProxyAuth` authentication option.
7+
6## Req 1.0.0
8## Req 1.0.0
7
9
8* Added the `reqBr` function allowing to consume `Response BodyReader`
10* Added the `reqBr` function allowing to consume `Response BodyReader`
Network/HTTP/Req.hs+12
@@ -178,6 +178,7 @@ module Network.HTTP.Req
178 -- $authentication
178 -- $authentication
179 , basicAuth
179 , basicAuth
180 , basicAuthUnsafe
180 , basicAuthUnsafe
181+ , basicProxyAuth
181 , oAuth1
182 , oAuth1
182 , oAuth2Bearer
183 , oAuth2Bearer
183 , oAuth2Token
184 , oAuth2Token
@@ -1284,6 +1285,17 @@ basicAuthUnsafe
1284basicAuthUnsafe username password = customAuth
1285basicAuthUnsafe username password = customAuth
1285 (pure . L.applyBasicAuth username password)
1286 (pure . L.applyBasicAuth username password)
1286
1287
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+
1287-- | The 'Option' adds OAuth1 authentication.
1299-- | The 'Option' adds OAuth1 authentication.
1288--
1300--
1289-- @since 0.2.0
1301-- @since 0.2.0
pure-tests/Network/HTTP/ReqSpec.hs+15
@@ -37,6 +37,7 @@ import qualified Data.Text as T
37import qualified Data.Text.Encoding as T
37import qualified Data.Text.Encoding as T
38import qualified Network.HTTP.Client as L
38import qualified Network.HTTP.Client as L
39import qualified Network.HTTP.Types as Y
39import qualified Network.HTTP.Types as Y
40+import qualified Network.HTTP.Types.Header as Y
40
41
41spec :: Spec
42spec :: Spec
42spec = do
43spec = do
@@ -238,6 +239,12 @@ spec = do
238 (oAuth2Bearer token0 <> oAuth2Bearer token1)
239 (oAuth2Bearer token0 <> oAuth2Bearer token1)
239 lookup "Authorization" (L.requestHeaders request) `shouldBe`
240 lookup "Authorization" (L.requestHeaders request) `shouldBe`
240 pure ("Bearer " <> token0)
241 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)
241 describe "oAuth2Token" $ do
248 describe "oAuth2Token" $ do
242 it "sets Authorization header to correct value" $
249 it "sets Authorization header to correct value" $
243 property $ \token -> do
250 property $ \token -> do
@@ -447,3 +454,11 @@ basicAuthHeader :: ByteString -> ByteString -> ByteString
447basicAuthHeader username password =
454basicAuthHeader username password =
448 fromJust . lookup Y.hAuthorization . L.requestHeaders $
455 fromJust . lookup Y.hAuthorization . L.requestHeaders $
449 L.applyBasicAuth username password L.defaultRequest
456 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