@@ -57,6 +57,8 @@ module Database.Bloodhound.Client
5757 , getStatus
5858 , encodeBulkOperations
5959 , encodeBulkOperation
60+ -- * Authentication
61+ , basicAuthHook
6062 -- * Reply-handling tools
6163 , isVersionConflict
6264 , isSuccess
@@ -767,3 +769,14 @@ isCreated = statusCheck (== 201)
767769
768770statusCheck :: (Int -> Bool) -> Reply -> Bool
769771statusCheck prd = prd . NHTS.statusCode . responseStatus
772+
773+-- | This is a hook that can be set via the 'bhRequestHook' function
774+-- that will authenticate all requests using an HTTP Basic
775+-- Authentication header. Note that it is *strongly* recommended that
776+-- this option only be used over an SSL connection.
777+--
778+-- >> (mkBHEnv myServer myManager) { bhRequestHook = basicAuthHook (EsUsername "myuser") (EsPassword "mypass") }
779+basicAuthHook :: EsUsername -> EsPassword -> Request -> IO Request
780+basicAuthHook (EsUsername u) (EsPassword p) = return . applyBasicAuth u' p'
781+ where u' = T.encodeUtf8 u
782+ p' = T.encodeUtf8 p