From 7c99e5402efe3c0f57f6b753cd72fe7a9a6c7181 Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Wed, 16 Apr 2025 04:14:54 +0530 Subject: [PATCH 1/2] Propagate managerWrapException setting in mkManagerSettingsContext' --- http-client-tls/Network/HTTP/Client/TLS.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http-client-tls/Network/HTTP/Client/TLS.hs b/http-client-tls/Network/HTTP/Client/TLS.hs index e0103335..71278958 100644 --- a/http-client-tls/Network/HTTP/Client/TLS.hs +++ b/http-client-tls/Network/HTTP/Client/TLS.hs @@ -97,7 +97,7 @@ mkManagerSettingsContext' set mcontext tls sockHTTP sockHTTPS = set | ((fromException e)::(Maybe TLS.TLSError))==Just TLS.Error_EOF -> True #endif | otherwise -> managerRetryableException defaultManagerSettings e - , managerWrapException = \req -> + , managerWrapException = \req act -> let wrapper se | Just (_ :: IOException) <- fromException se = se' | Just (_ :: TLS.TLSException) <- fromException se = se' @@ -110,7 +110,7 @@ mkManagerSettingsContext' set mcontext tls sockHTTP sockHTTPS = set | otherwise = se where se' = toException $ HttpExceptionRequest req $ InternalException se - in handle $ throwIO . wrapper + in handle (throwIO . wrapper) (managerWrapException set req act) } -- | Default TLS-enabled manager settings From 9b4c061d92d786705c7f54e354b66e1db83e2dde Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Fri, 18 Apr 2025 19:12:55 +0530 Subject: [PATCH 2/2] Add a test case in http-client-tls checking the setting propagation --- http-client-tls/test/Spec.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/http-client-tls/test/Spec.hs b/http-client-tls/test/Spec.hs index 010a8c3d..3878e6e5 100644 --- a/http-client-tls/test/Spec.hs +++ b/http-client-tls/test/Spec.hs @@ -1,5 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} + +import Data.IORef (newIORef, readIORef, modifyIORef') import Test.Hspec import Network.Connection import Network.HTTP.Client @@ -85,3 +87,14 @@ main = hspec $ do request <- parseRequest "https://httpbin.org" response <- httpNoBody request manager responseStatus response `shouldBe` status200 + + it "propagates input manager settings" $ do + ref <- newIORef 0 + let + tlsManagerSettings' = tlsManagerSettings + { managerWrapException = \_ act -> modifyIORef' ref (+1) >> act + } + manager <- newTlsManagerWith tlsManagerSettings' + request <- parseRequest "https://httpbin.org" + _ <- httpNoBody request manager + readIORef ref `shouldReturn` 1