[refactor] upgrade servant-client to 0.20

parent 229fdf40
...@@ -32,6 +32,7 @@ library ...@@ -32,6 +32,7 @@ library
HAL.Doc.Document HAL.Doc.Document
HAL.Doc.EntityTree HAL.Doc.EntityTree
HAL.Doc.Struct HAL.Doc.Struct
HAL.ServantClientLogging
HAL.Types HAL.Types
HAL.Utils HAL.Utils
Tree Tree
...@@ -51,6 +52,7 @@ library ...@@ -51,6 +52,7 @@ library
build-depends: build-depends:
aeson >= 1.5.6 && < 2.3 aeson >= 1.5.6 && < 2.3
, base >=4.7 && <5 , base >=4.7 && <5
, binary >= 0.8.8 && < 0.9
, bytestring >= 0.11.0 && < 0.13 , bytestring >= 0.11.0 && < 0.13
, conduit >= 1.3.5 && < 1.4 , conduit >= 1.3.5 && < 1.4
, containers >= 0.6.7 && < 0.7 , containers >= 0.6.7 && < 0.7
...@@ -63,8 +65,9 @@ library ...@@ -63,8 +65,9 @@ library
, optparse-applicative >= 0.17 && < 0.19 , optparse-applicative >= 0.17 && < 0.19
, protolude >= 0.3.3 && < 0.4 , protolude >= 0.3.3 && < 0.4
, scientific >= 0.3.7.0 && < 0.4 , scientific >= 0.3.7.0 && < 0.4
, servant >= 0.19 && < 0.20 , servant >= 0.20 && < 0.21
, servant-client >= 0.19 && < 0.20 , servant-client >= 0.20 && < 0.21
, servant-client-core >= 0.20 && < 0.21
, split >= 0.2.3.5 && < 0.3 , split >= 0.2.3.5 && < 0.3
, text >= 1.2.3.0 && < 2.1 , text >= 1.2.3.0 && < 2.1
, text-format >= 0.3.2.1 && < 0.4 , text-format >= 0.3.2.1 && < 0.4
...@@ -100,7 +103,7 @@ executable crawlerHAL-exe ...@@ -100,7 +103,7 @@ executable crawlerHAL-exe
, iso639 >= 0.1.0.3 && < 0.2 , iso639 >= 0.1.0.3 && < 0.2
, optparse-applicative >= 0.17 && < 0.19 , optparse-applicative >= 0.17 && < 0.19
, protolude >= 0.3.3 && < 0.4 , protolude >= 0.3.3 && < 0.4
, servant-client >= 0.19 && < 0.21 , servant-client >= 0.20 && < 0.21
, split >= 0.2.3.5 && < 0.3 , split >= 0.2.3.5 && < 0.3
, text >= 1.2.3.0 && < 2.1 , text >= 1.2.3.0 && < 2.1
default-language: Haskell2010 default-language: Haskell2010
......
...@@ -8,14 +8,14 @@ import Data.Text qualified as T ...@@ -8,14 +8,14 @@ import Data.Text qualified as T
import HAL.Client ( SortField(Asc), search, structure, searchCursor ) import HAL.Client ( SortField(Asc), search, structure, searchCursor )
import HAL.Doc.Document ( Document(..) ) import HAL.Doc.Document ( Document(..) )
import HAL.Doc.Struct ( Struct ) import HAL.Doc.Struct ( Struct )
import HAL.ServantClientLogging (addLoggingToClientEnv)
import HAL.Types (Response(..)) import HAL.Types (Response(..))
import HAL.Utils (langAbstractS, toText) import HAL.Utils (langAbstractS, toText)
import Network.HTTP.Client (newManager, Request) import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings) import Network.HTTP.Client.TLS (tlsManagerSettings)
import Protolude import Protolude
import Servant.API ( ToHttpApiData ) import Servant.API ( ToHttpApiData )
import Servant.Client (BaseUrl(..), Scheme(..), ClientM, ClientError, runClientM, mkClientEnv, ClientEnv (makeClientRequest)) import Servant.Client (BaseUrl(..), Scheme(..), ClientM, ClientError, runClientM, mkClientEnv)
import System.IO.Unsafe (unsafePerformIO)
data HalCrawlerOptions data HalCrawlerOptions
...@@ -237,23 +237,14 @@ baseFields = [ "docid" ...@@ -237,23 +237,14 @@ baseFields = [ "docid"
structFields :: Text structFields :: Text
structFields = "docid,label_s,parentDocid_i" structFields = "docid,label_s,parentDocid_i"
requestLog :: HalCrawlerOptions -> Request -> Request
requestLog opts rq = unsafePerformIO $ do
debugLog opts $ "[HAL.makeClientRequestLog] " <> show rq
pure rq
{-# NOINLINE requestLog #-}
runHalAPIClient :: (FromJSON doc, ToHttpApiData doc) runHalAPIClient :: (FromJSON doc, ToHttpApiData doc)
=> HalCrawlerOptions => HalCrawlerOptions
-> ClientM (Response doc) -> ClientM (Response doc)
-> IO (Either ClientError (Response doc)) -> IO (Either ClientError (Response doc))
runHalAPIClient opts cmd = do runHalAPIClient _opts cmd = do
manager' <- newManager tlsManagerSettings manager' <- newManager tlsManagerSettings
runClientM cmd' (mkClientEnv manager' $ BaseUrl Https "api.archives-ouvertes.fr" 443 "") let env = mkClientEnv manager' $ BaseUrl Https "api.archives-ouvertes.fr" 443 ""
where runClientM cmd $ addLoggingToClientEnv env
cmd' = local (\r -> r {
makeClientRequest = \bUrl servantRq -> requestLog opts (makeClientRequest r bUrl servantRq)
}) cmd
runStructureRequest :: Maybe Text -> IO (Either ClientError (Response Struct)) runStructureRequest :: Maybe Text -> IO (Either ClientError (Response Struct))
runStructureRequest rq = runStructureRequest rq =
......
{-|
Module : HAL.ServantClientLogging
Description : Textmining Collaborative Platform
Copyright : (c) CNRS, 2023-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
@Gargantext@: search, map, share
-}
{-# LANGUAGE FlexibleContexts #-}
module HAL.ServantClientLogging where
import Data.Binary.Builder qualified as DBB
import Debug.Trace (trace)
import Protolude hiding (trace)
import Servant.Client (ClientEnv(..))
import Servant.Client.Core.Request (RequestF(..))
addLoggingToClientEnv :: ClientEnv -> ClientEnv
addLoggingToClientEnv env@(ClientEnv { makeClientRequest = mcr }) = env { makeClientRequest }
where
makeClientRequest baseUrl req =
trace ("req: " <> showRequestPath req <> " " <> show (requestQueryString req)) $ mcr baseUrl req
showRequestPath req =
show $ DBB.toLazyByteString $ requestPath req
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment