@@ -170,6 +170,7 @@ module Network.HTTP.Req
170170 , QueryParam (..)
171171 -- *** Headers
172172 , header
173+ , attachHeader
173174 -- *** Cookies
174175 -- $cookies
175176 , cookieJar
@@ -180,6 +181,7 @@ module Network.HTTP.Req
180181 , oAuth1
181182 , oAuth2Bearer
182183 , oAuth2Token
184+ , customAuth
183185 -- *** Other
184186 , port
185187 , decompress
@@ -1143,12 +1145,6 @@ withQueryParams f = Option (Endo (first f)) Nothing
11431145withRequest :: (L.Request -> L.Request) -> Option scheme
11441146withRequest f = Option (Endo (second f)) Nothing
11451147
1146−-- | A helper to create an 'Option' that adds a finalizer (an IO-enabled
1147−-- request transformation that is applied after all other modifications).
1148−
1149−asFinalizer :: (L.Request -> IO L.Request) -> Option scheme
1150−asFinalizer = Option mempty . pure
1151−
11521148instance RequestComponent (Option scheme) where
11531149 getRequestMod (Option f _) = Endo $ \x ->
11541150 let (qparams, x') = appEndo f ([], x)
@@ -1229,6 +1225,8 @@ header name value = withRequest (attachHeader name value)
12291225
12301226-- | A non-public helper that attaches a header with given name and content
12311227-- to a 'L.Request'.
1228+--
1229+-- @since 1.1.0
12321230
12331231attachHeader :: ByteString -> ByteString -> L.Request -> L.Request
12341232attachHeader name value x =
@@ -1283,7 +1281,7 @@ basicAuthUnsafe
12831281 :: ByteString -- ^ Username
12841282 -> ByteString -- ^ Password
12851283 -> Option scheme -- ^ Auth 'Option'
1286−basicAuthUnsafe username password = asFinalizer
1284+basicAuthUnsafe username password = customAuth
12871285 (pure . L.applyBasicAuth username password)
12881286
12891287-- | The 'Option' adds OAuth1 authentication.
@@ -1297,7 +1295,7 @@ oAuth1
12971295 -> ByteString -- ^ OAuth token secret
12981296 -> Option scheme -- ^ Auth 'Option'
12991297oAuth1 consumerToken consumerSecret token tokenSecret =
1300− asFinalizer (OAuth.signOAuth app creds)
1298+ customAuth (OAuth.signOAuth app creds)
13011299 where
13021300 app = OAuth.newOAuth
13031301 { OAuth.oauthConsumerKey = consumerToken
@@ -1316,7 +1314,7 @@ oAuth1 consumerToken consumerSecret token tokenSecret =
13161314oAuth2Bearer
13171315 :: ByteString -- ^ Token
13181316 -> Option 'Https -- ^ Auth 'Option'
1319−oAuth2Bearer token = asFinalizer
1317+oAuth2Bearer token = customAuth
13201318 (pure . attachHeader "Authorization" ("Bearer " <> token))
13211319
13221320-- | The 'Option' adds a not-quite-standard OAuth2 bearer token (that seems
@@ -1332,9 +1330,18 @@ oAuth2Bearer token = asFinalizer
13321330oAuth2Token
13331331 :: ByteString -- ^ Token
13341332 -> Option 'Https -- ^ Auth 'Option'
1335−oAuth2Token token = asFinalizer
1333+oAuth2Token token = customAuth
13361334 (pure . attachHeader "Authorization" ("token " <> token))
13371335
1336+-- | A helper to create custom authentication 'Option's. The given
1337+-- 'IO'-enabled request transformation is applied after all other
1338+-- modifications when constructing a request. Use wisely.
1339+--
1340+-- @since 1.1.0
1341+
1342+customAuth :: (L.Request -> IO L.Request) -> Option scheme
1343+customAuth = Option mempty . pure
1344+
13381345----------------------------------------------------------------------------
13391346-- Request—Optional parameters—Other
13401347