{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Servant.Client.Core.BasicAuth (
basicAuthReq,
) where
import Data.ByteString.Base64
(encode)
import Data.Text.Encoding
(decodeUtf8)
import Servant.API.BasicAuth
(BasicAuthData (BasicAuthData))
import Servant.Client.Core.Request
(Request, addHeader)
basicAuthReq :: BasicAuthData -> Request -> Request
basicAuthReq :: BasicAuthData -> Request -> Request
basicAuthReq (BasicAuthData ByteString
user ByteString
pass) Request
req =
let authText :: Text
authText = ByteString -> Text
decodeUtf8 (ByteString
"Basic " ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString -> ByteString
encode (ByteString
user ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
":" ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
pass))
in HeaderName -> Text -> Request -> Request
forall a. ToHttpApiData a => HeaderName -> a -> Request -> Request
addHeader HeaderName
"Authorization" Text
authText Request
req