Skip to content

simpleHTTP: Catch IOException from openStream and turn it into Result #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Network/HTTP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ import Network.HTTP.Base
import qualified Network.HTTP.HandleStream as S
-- old implementation: import Network.HTTP.Stream
import Network.TCP
import Network.Stream ( Result )
import Network.Stream ( Result, failMisc )
import Network.URI ( parseURI )

import Control.Exception ( IOException, try )
import Data.Maybe ( fromMaybe )

{-
Expand All @@ -106,9 +107,10 @@ simpleHTTP :: (HStream ty) => Request ty -> IO (Result (Response ty))
simpleHTTP r = do
auth <- getAuth r
failHTTPS (rqURI r)
c <- openStream (host auth) (fromMaybe 80 (port auth))
let norm_r = normalizeRequest defaultNormalizeRequestOptions{normDoClose=True} r
simpleHTTP_ c norm_r
c <- try (openStream (host auth) (fromMaybe 80 (port auth)))
case c of
Left err -> return . failMisc $ show (err :: IOException)
Right c' -> simpleHTTP_ c' r

-- | Identical to 'simpleHTTP', but acting on an already opened stream.
simpleHTTP_ :: HStream ty => HandleStream ty -> Request ty -> IO (Result (Response ty))
Expand Down