-- 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.1.0.1

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 :: forall env a. HasTerm env => RetryPolicy -> RIO env a -> RIO env a

-- | A request together with some checks to perform.
data DownloadRequest
DownloadRequest :: Request -> [HashCheck] -> Maybe LengthCheck -> RetryPolicy -> DownloadRequest
[drRequest] :: DownloadRequest -> Request
[drHashChecks] :: DownloadRequest -> [HashCheck]
[drLengthCheck] :: DownloadRequest -> Maybe LengthCheck
[drRetryPolicy] :: DownloadRequest -> RetryPolicy

-- | Default to retrying seven times with exponential backoff starting from
--   one hundred milliseconds.
--   
--   This means the tries will occur after these delays if necessary:
--   
--   <ul>
--   <li>0.1s</li>
--   <li>0.2s</li>
--   <li>0.4s</li>
--   <li>0.8s</li>
--   <li>1.6s</li>
--   <li>3.2s</li>
--   <li>6.4s</li>
--   </ul>
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
instance GHC.Show.Show Network.HTTP.Download.Verified.CheckHexDigest
instance GHC.Show.Show Network.HTTP.Download.Verified.VerifyFileException
instance GHC.Show.Show Network.HTTP.Download.Verified.HashCheck
instance GHC.Exception.Type.Exception Network.HTTP.Download.Verified.VerifyFileException
instance GHC.Show.Show Network.HTTP.Download.Verified.VerifiedDownloadException
instance GHC.Exception.Type.Exception Network.HTTP.Download.Verified.VerifiedDownloadException
instance Data.String.IsString Network.HTTP.Download.Verified.CheckHexDigest

module Network.HTTP.Download

-- | A request together with some checks to perform.
data DownloadRequest
DownloadRequest :: Request -> [HashCheck] -> Maybe LengthCheck -> RetryPolicy -> DownloadRequest
[drRequest] :: DownloadRequest -> Request
[drHashChecks] :: DownloadRequest -> [HashCheck]
[drLengthCheck] :: DownloadRequest -> Maybe LengthCheck
[drRetryPolicy] :: DownloadRequest -> RetryPolicy

-- | Default to retrying seven times with exponential backoff starting from
--   one hundred milliseconds.
--   
--   This means the tries will occur after these delays if necessary:
--   
--   <ul>
--   <li>0.1s</li>
--   <li>0.2s</li>
--   <li>0.4s</li>
--   <li>0.8s</li>
--   <li>1.6s</li>
--   <li>3.2s</li>
--   <li>6.4s</li>
--   </ul>
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

-- | 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 <a>download</a>, but will download a file a second time if it
--   is already present.
--   
--   Returns <a>True</a> if the file was downloaded, <a>False</a> 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.Show.Show Network.HTTP.Download.DownloadException
instance GHC.Exception.Type.Exception Network.HTTP.Download.DownloadException
