-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Verified downloads with retries
--   
--   Higher level HTTP download APIs include verification of content and
--   retries
@package http-download
@version 0.2.1.0

module Network.HTTP.Download.Verified

-- | Copied and extended version of Network.HTTP.Download.download.
--   
--   Has the following additional features: * Verifies that response
--   content-length header (if present) matches expected length * Limits
--   the download to (close to) the expected # of bytes * Verifies that the
--   expected # bytes were downloaded (not too few) * Verifies md5 if
--   response includes content-md5 header * Verifies the expected hashes
--   
--   Throws VerifiedDownloadException. Throws IOExceptions related to file
--   system operations. Throws HttpException.
verifiedDownload :: HasTerm env => DownloadRequest -> Path Abs File -> (Maybe Integer -> ConduitM ByteString Void (RIO env) ()) -> RIO env Bool
recoveringHttp :: HasTerm env => RetryPolicy -> RIO env a -> RIO env a

-- | Default to retrying seven times with exponential backoff starting from
--   one hundred milliseconds.
--   
--   This means the tries will occur after these delays if necessary:
--   
--   
--   
- 0.1s
--   
- 0.2s
--   
- 0.4s
--   
- 0.8s
--   
- 1.6s
--   
- 3.2s
--   
- 6.4s
--   
drRetryPolicyDefault :: RetryPolicy
data HashCheck
HashCheck :: a -> CheckHexDigest -> HashCheck
[hashCheckAlgorithm] :: HashCheck -> a
[hashCheckHexDigest] :: HashCheck -> CheckHexDigest
data CheckHexDigest
CheckHexDigestString :: String -> CheckHexDigest
CheckHexDigestByteString :: ByteString -> CheckHexDigest
CheckHexDigestHeader :: ByteString -> CheckHexDigest
type LengthCheck = Int

-- | An exception regarding verification of a download.
data VerifiedDownloadException
WrongContentLength :: Request -> Int -> ByteString -> VerifiedDownloadException
WrongStreamLength :: Request -> Int -> Int -> VerifiedDownloadException
WrongDigest :: Request -> String -> CheckHexDigest -> String -> VerifiedDownloadException
DownloadHttpError :: HttpException -> VerifiedDownloadException

-- | A request together with some checks to perform.
--   
--   Construct using the downloadRequest smart constructor and
--   associated setters. The constructor itself is not exposed to avoid
--   breaking changes with additional fields.
data DownloadRequest

-- | Construct a new DownloadRequest from the given Request.
--   Use associated setters to modify the value further.
mkDownloadRequest :: Request -> DownloadRequest

-- | Modify the Request inside a DownloadRequest. Especially
--   intended for modifying the User-Agent request header.
modifyRequest :: (Request -> Request) -> DownloadRequest -> DownloadRequest

-- | Set the hash checks to be run when verifying.
setHashChecks :: [HashCheck] -> DownloadRequest -> DownloadRequest

-- | Set the length check to be run when verifying.
setLengthCheck :: Maybe LengthCheck -> DownloadRequest -> DownloadRequest

-- | Set the retry policy to be used when downloading.
setRetryPolicy :: RetryPolicy -> DownloadRequest -> DownloadRequest

-- | If True, force download even if the file already exists. Useful
--   for download a resource which may change over time.
setForceDownload :: Bool -> DownloadRequest -> DownloadRequest
instance GHC.Internal.Exception.Type.Exception Network.HTTP.Download.Verified.VerifiedDownloadException
instance GHC.Internal.Exception.Type.Exception Network.HTTP.Download.Verified.VerifyFileException
instance GHC.Internal.Data.String.IsString Network.HTTP.Download.Verified.CheckHexDigest
instance GHC.Internal.Show.Show Network.HTTP.Download.Verified.CheckHexDigest
instance GHC.Internal.Show.Show Network.HTTP.Download.Verified.HashCheck
instance GHC.Internal.Show.Show Network.HTTP.Download.Verified.VerifiedDownloadException
instance GHC.Internal.Show.Show Network.HTTP.Download.Verified.VerifyFileException

module Network.HTTP.Download

-- | A request together with some checks to perform.
--   
--   Construct using the downloadRequest smart constructor and
--   associated setters. The constructor itself is not exposed to avoid
--   breaking changes with additional fields.
data DownloadRequest

-- | Construct a new DownloadRequest from the given Request.
--   Use associated setters to modify the value further.
mkDownloadRequest :: Request -> DownloadRequest

-- | Modify the Request inside a DownloadRequest. Especially
--   intended for modifying the User-Agent request header.
modifyRequest :: (Request -> Request) -> DownloadRequest -> DownloadRequest

-- | Set the hash checks to be run when verifying.
setHashChecks :: [HashCheck] -> DownloadRequest -> DownloadRequest

-- | Set the length check to be run when verifying.
setLengthCheck :: Maybe LengthCheck -> DownloadRequest -> DownloadRequest

-- | Set the retry policy to be used when downloading.
setRetryPolicy :: RetryPolicy -> DownloadRequest -> DownloadRequest

-- | If True, force download even if the file already exists. Useful
--   for download a resource which may change over time.
setForceDownload :: Bool -> DownloadRequest -> DownloadRequest

-- | Default to retrying seven times with exponential backoff starting from
--   one hundred milliseconds.
--   
--   This means the tries will occur after these delays if necessary:
--   
--   
--   
- 0.1s
--   
- 0.2s
--   
- 0.4s
--   
- 0.8s
--   
- 1.6s
--   
- 3.2s
--   
- 6.4s
--   
drRetryPolicyDefault :: RetryPolicy
data HashCheck
HashCheck :: a -> CheckHexDigest -> HashCheck
[hashCheckAlgorithm] :: HashCheck -> a
[hashCheckHexDigest] :: HashCheck -> CheckHexDigest
data DownloadException
RedownloadInvalidResponse :: Request -> Path Abs File -> Response () -> DownloadException
RedownloadHttpError :: HttpException -> DownloadException
data CheckHexDigest
CheckHexDigestString :: String -> CheckHexDigest
CheckHexDigestByteString :: ByteString -> CheckHexDigest
CheckHexDigestHeader :: ByteString -> CheckHexDigest
type LengthCheck = Int

-- | An exception regarding verification of a download.
data VerifiedDownloadException
WrongContentLength :: Request -> Int -> ByteString -> VerifiedDownloadException
WrongStreamLength :: Request -> Int -> Int -> VerifiedDownloadException
WrongDigest :: Request -> String -> CheckHexDigest -> String -> VerifiedDownloadException
DownloadHttpError :: HttpException -> VerifiedDownloadException

-- | Download the given URL to the given location. If the file already
--   exists, no download is performed. Otherwise, creates the parent
--   directory, downloads to a temporary file, and on file download
--   completion moves to the appropriate destination.
--   
--   Throws an exception if things go wrong
download :: HasTerm env => Request -> Path Abs File -> RIO env Bool

-- | Same as download, but will download a file a second time if it
--   is already present.
--   
--   Returns True if the file was downloaded, False otherwise
redownload :: HasTerm env => Request -> Path Abs File -> RIO env Bool

-- | Copied and extended version of Network.HTTP.Download.download.
--   
--   Has the following additional features: * Verifies that response
--   content-length header (if present) matches expected length * Limits
--   the download to (close to) the expected # of bytes * Verifies that the
--   expected # bytes were downloaded (not too few) * Verifies md5 if
--   response includes content-md5 header * Verifies the expected hashes
--   
--   Throws VerifiedDownloadException. Throws IOExceptions related to file
--   system operations. Throws HttpException.
verifiedDownload :: HasTerm env => DownloadRequest -> Path Abs File -> (Maybe Integer -> ConduitM ByteString Void (RIO env) ()) -> RIO env Bool
instance GHC.Internal.Exception.Type.Exception Network.HTTP.Download.DownloadException
instance GHC.Internal.Show.Show Network.HTTP.Download.DownloadException
