http-download-0.2.1.0: Verified downloads with retries

Safe Haskell | None
Language | Haskell2010

Network.HTTP.Download

Synopsis

- data DownloadRequest
- mkDownloadRequest :: Request -> DownloadRequest
- modifyRequest :: (Request -> Request) -> DownloadRequest -> DownloadRequest
- setHashChecks :: [HashCheck] -> DownloadRequest -> DownloadRequest
- setLengthCheck :: Maybe LengthCheck -> DownloadRequest -> DownloadRequest
- setRetryPolicy :: RetryPolicy -> DownloadRequest -> DownloadRequest
- setForceDownload :: Bool -> DownloadRequest -> DownloadRequest
- drRetryPolicyDefault :: RetryPolicy
- data HashCheck = (Show a, HashAlgorithm a) => HashCheck {
  - hashCheckAlgorithm :: a
  - hashCheckHexDigest :: CheckHexDigest
  }
- data DownloadException
  - = RedownloadInvalidResponse Request (Path Abs File) (Response ())
  - | RedownloadHttpError HttpException
- data CheckHexDigest
  - = CheckHexDigestString String
  - | CheckHexDigestByteString ByteString
  - | CheckHexDigestHeader ByteString
- type LengthCheck = Int
- data VerifiedDownloadException
  - = WrongContentLength Request Int ByteString
  - | WrongStreamLength Request Int Int
  - | WrongDigest Request String CheckHexDigest String
  - | DownloadHttpError HttpException
- download :: HasTerm env => Request -> Path Abs File -> RIO env Bool
- redownload :: HasTerm env => Request -> Path Abs File -> RIO env Bool
- verifiedDownload :: HasTerm env => DownloadRequest -> Path Abs File -> (Maybe Integer -> ConduitM ByteString Void (RIO env) ()) -> RIO env Bool

# Documentation

data DownloadRequest Source #

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.

Since: 0.2.0.0

mkDownloadRequest :: Request -> DownloadRequest Source #

Construct a new `DownloadRequest` from the given `Request`. Use associated setters to modify the value further.

Since: 0.2.0.0

modifyRequest :: (Request -> Request) -> DownloadRequest -> DownloadRequest Source #

Modify the `Request` inside a `DownloadRequest`. Especially intended for modifying the `User-Agent` request header.

Since: 0.2.0.0

setHashChecks :: [HashCheck] -> DownloadRequest -> DownloadRequest Source #

Set the hash checks to be run when verifying.

Since: 0.2.0.0

setLengthCheck :: Maybe LengthCheck -> DownloadRequest -> DownloadRequest Source #

Set the length check to be run when verifying.

Since: 0.2.0.0

setRetryPolicy :: RetryPolicy -> DownloadRequest -> DownloadRequest Source #

Set the retry policy to be used when downloading.

Since: 0.2.0.0

setForceDownload :: Bool -> DownloadRequest -> DownloadRequest Source #

If `True`, force download even if the file already exists. Useful for download a resource which may change over time.

drRetryPolicyDefault :: RetryPolicy Source #

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

data HashCheck Source #

Constructors

(Show a, HashAlgorithm a) => HashCheck |

Fields

- hashCheckAlgorithm :: a
- hashCheckHexDigest :: CheckHexDigest

#### Instances

Instances details

Show HashCheck Source # |
Instance details Defined in Network.HTTP.Download.Verified Methods showsPrec :: Int -> HashCheck -> ShowS Source # show :: HashCheck -> String Source # showList :: [HashCheck] -> ShowS Source #

data DownloadException Source #

Constructors

RedownloadInvalidResponse Request (Path Abs File) (Response ()) |
RedownloadHttpError HttpException |

#### Instances

Instances details

Exception DownloadException Source # |
Instance details Defined in Network.HTTP.Download Methods toException :: DownloadException -> SomeException Source # fromException :: SomeException -> Maybe DownloadException Source # displayException :: DownloadException -> String Source # backtraceDesired :: DownloadException -> Bool Source #
Show DownloadException Source # |
Instance details Defined in Network.HTTP.Download Methods showsPrec :: Int -> DownloadException -> ShowS Source # show :: DownloadException -> String Source # showList :: [DownloadException] -> ShowS Source #

data CheckHexDigest Source #

Constructors

CheckHexDigestString String |
CheckHexDigestByteString ByteString |
CheckHexDigestHeader ByteString |

#### Instances

Instances details

IsString CheckHexDigest Source # |
Instance details Defined in Network.HTTP.Download.Verified Methods fromString :: String -> CheckHexDigest Source #
Show CheckHexDigest Source # |
Instance details Defined in Network.HTTP.Download.Verified Methods showsPrec :: Int -> CheckHexDigest -> ShowS Source # show :: CheckHexDigest -> String Source # showList :: [CheckHexDigest] -> ShowS Source #

type LengthCheck = Int Source #

data VerifiedDownloadException Source #

An exception regarding verification of a download.

Constructors

WrongContentLength Request Int ByteString |
WrongStreamLength Request Int Int |
WrongDigest Request String CheckHexDigest String |
DownloadHttpError HttpException |

#### Instances

Instances details

Exception VerifiedDownloadException Source # |
Instance details Defined in Network.HTTP.Download.Verified Methods toException :: VerifiedDownloadException -> SomeException Source # fromException :: SomeException -> Maybe VerifiedDownloadException Source # displayException :: VerifiedDownloadException -> String Source # backtraceDesired :: VerifiedDownloadException -> Bool Source #
Show VerifiedDownloadException Source # |
Instance details Defined in Network.HTTP.Download.Verified Methods showsPrec :: Int -> VerifiedDownloadException -> ShowS Source # show :: VerifiedDownloadException -> String Source # showList :: [VerifiedDownloadException] -> ShowS Source #

download Source #

Arguments

:: HasTerm env |
=> Request |
-> Path Abs File | destination
-> RIO env Bool | Was a downloaded performed (True) or did the file already exist (False)?

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

redownload Source #

Arguments

:: HasTerm env |
=> Request |
-> Path Abs File | destination
-> 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

verifiedDownload Source #

Arguments

:: HasTerm env |
=> DownloadRequest |
-> Path Abs File | destination
-> (Maybe Integer -> ConduitM ByteString Void (RIO env) ()) | custom hook to observe progress
-> RIO env Bool | Whether a download was performed

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.