Browse files

Handle exceptions thrown during reading the response header

  • Loading branch information...
1 parent c1da8cf commit 77e8c6438af599a4f819172204ece5a0c4d6a16e @snoyberg committed Apr 19, 2012
Showing with 16 additions and 5 deletions.
  1. +15 −4 Network/HTTP/Conduit.hs
  2. +1 −1 http-conduit.cabal
View
19 Network/HTTP/Conduit.hs
@@ -195,17 +195,28 @@ httpRaw
httpRaw req m = do
(connRelease, ci, isManaged) <- getConn req m
let src = connSource ci
- ex <- try $ requestBuilder req C.$$ builderToByteString C.=$ connSink ci
- case (ex :: Either SomeException (), isManaged) of
+
+ -- Originally, we would only test for exceptions when sending the request,
+ -- not on calling @getResponse@. However, some servers seem to close
+ -- connections after accepting the request headers, so we need to check for
+ -- exceptions in both.
+ ex <- try' $ do
+ requestBuilder req C.$$ builderToByteString C.=$ connSink ci
+ getResponse connRelease req src
+
+ case (ex, isManaged) of
-- Connection was reused, and might be been closed. Try again
(Left _, Reused) -> do
connRelease DontReuse
http req m
-- Not reused, so this is a real exception
(Left e, Fresh) -> liftIO $ throwIO e
-- Everything went ok, so the connection is good. If any exceptions get
- -- thrown in the rest of the code, just throw them as normal.
- (Right (), _) -> getResponse connRelease req src
+ -- thrown in the response body, just throw them as normal.
+ (Right x, _) -> return x
+ where
+ try' :: MonadBaseControl IO m => m a -> m (Either SomeException a)
+ try' = try
-- | Download the specified 'Request', returning the results as a 'Response'.
--
View
2 http-conduit.cabal
@@ -1,5 +1,5 @@
name: http-conduit
-version: 1.4.1.1
+version: 1.4.1.2
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>

0 comments on commit 77e8c64

Please sign in to comment.