-- 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 :: forall env a. 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:
--   
--   <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
DownloadHttpError :: HttpException -> VerifiedDownloadException

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

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

-- | Modify the <a>Request</a> inside a <a>DownloadRequest</a>. Especially
--   intended for modifying the <tt>User-Agent</tt> 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 <a>True</a>, force download even if the file already exists. Useful
--   for download a resource which may change over time.
setForceDownload :: Bool -> DownloadRequest -> DownloadRequest
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.
--   
--   Construct using the <tt>downloadRequest</tt> smart constructor and
--   associated setters. The constructor itself is not exposed to avoid
--   breaking changes with additional fields.
data DownloadRequest

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

-- | Modify the <a>Request</a> inside a <a>DownloadRequest</a>. Especially
--   intended for modifying the <tt>User-Agent</tt> 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 <a>True</a>, 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:
--   
--   <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
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 <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
