module Unison.Util.HTTP (addRequestMiddleware, setUserAgent, ucmUserAgent) where import Data.Text.Encoding qualified as Text import Network.HTTP.Client qualified as HTTP import Unison.Codebase.Editor.UCMVersion (UCMVersion) import Unison.Prelude addRequestMiddleware :: (HTTP.Request -> IO HTTP.Request) -> HTTP.ManagerSettings -> HTTP.ManagerSettings addRequestMiddleware :: (Request -> IO Request) -> ManagerSettings -> ManagerSettings addRequestMiddleware Request -> IO Request f ManagerSettings man = ManagerSettings man {HTTP.managerModifyRequest = (HTTP.managerModifyRequest man) >=> f} ucmUserAgent :: UCMVersion -> Text ucmUserAgent :: Text -> Text ucmUserAgent Text ucmVersion = Text "UCM/" Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text ucmVersion setUserAgent :: Text -> HTTP.ManagerSettings -> HTTP.ManagerSettings setUserAgent :: Text -> ManagerSettings -> ManagerSettings setUserAgent Text userAgent = let addUserAgent :: Request -> IO Request addUserAgent Request req = do Request -> IO Request forall a. a -> IO a forall (f :: * -> *) a. Applicative f => a -> f a pure (Request -> IO Request) -> Request -> IO Request forall a b. (a -> b) -> a -> b $ Request req {HTTP.requestHeaders = ("User-Agent", Text.encodeUtf8 userAgent) : HTTP.requestHeaders req} in (Request -> IO Request) -> ManagerSettings -> ManagerSettings addRequestMiddleware Request -> IO Request addUserAgent