99module Network.HTTP.Download.Verified
1010 ( verifiedDownload
1111 , DownloadRequest (.. )
12- , drRetriesDefault
12+ , drRetryPolicyDefault
1313 , HashCheck (.. )
1414 , CheckHexDigest (.. )
1515 , LengthCheck
@@ -28,7 +28,7 @@ import Control.Monad
2828import Control.Monad.Catch
2929import Control.Monad.IO.Class
3030import Control.Monad.Reader
31- import Control.Retry (recovering ,limitRetries )
31+ import Control.Retry (recovering ,limitRetries , RetryPolicy , constantDelay )
3232import Control.Applicative
3333import Crypto.Hash
3434import Crypto.Hash.Conduit (sinkHash )
@@ -53,13 +53,13 @@ data DownloadRequest = DownloadRequest
5353 { drRequest :: Request
5454 , drHashChecks :: [HashCheck ]
5555 , drLengthCheck :: Maybe LengthCheck
56- , drRetries :: Int
56+ , drRetryPolicy :: RetryPolicy
5757 }
58- deriving Show
5958
60- -- | Default to retrying thrice.
61- drRetriesDefault :: Int
62- drRetriesDefault = 3
59+ -- | Default to retrying thrice with a short constant delay.
60+ drRetryPolicyDefault :: RetryPolicy
61+ drRetryPolicyDefault = limitRetries 3 <> constantDelay onehundredMilliseconds
62+ where onehundredMilliseconds = 100000
6363
6464data HashCheck = forall a . (Show a , HashAlgorithm a ) => HashCheck
6565 { hashCheckAlgorithm :: a
@@ -200,7 +200,7 @@ verifiedDownload DownloadRequest{..} destpath progressSink = do
200200 liftIO $ whenM' getShouldDownload $ do
201201 createDirectoryIfMissing True dir
202202 withBinaryFile fptmp WriteMode $ \ h -> do
203- recovering (limitRetries drRetries) [const $ Handler alwaysRetryHttp] $
203+ recovering drRetryPolicy [const $ Handler alwaysRetryHttp] $
204204 flip runReaderT env $
205205 withResponse req (go h)
206206 renameFile fptmp fp
0 commit comments