stack-1.4.0: The Haskell Tool Stack

Safe Haskell | None
Language | Haskell2010

Network.HTTP.Download.Verified

Synopsis

- verifiedDownload :: (MonadIO m, MonadLogger m) => DownloadRequest -> Path Abs File -> (Maybe Integer -> Sink ByteString IO ()) -> m Bool
- recoveringHttp :: (MonadMask m, MonadIO m) => RetryPolicy -> m a -> m a
- data DownloadRequest = DownloadRequest {
  - drRequest :: Request
  - drHashChecks :: [HashCheck]
  - drLengthCheck :: Maybe LengthCheck
  - drRetryPolicy :: RetryPolicy
  }
- drRetryPolicyDefault :: RetryPolicy
- data HashCheck = (Show a, HashAlgorithm a) => HashCheck {
  - hashCheckAlgorithm :: a
  - hashCheckHexDigest :: CheckHexDigest
  }
- 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

# Documentation

verifiedDownload #

Arguments

:: (MonadIO m, MonadLogger m) |
=> DownloadRequest |
-> Path Abs File | destination
-> (Maybe Integer -> Sink ByteString IO ()) | custom hook to observe progress
-> m 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.

recoveringHttp :: (MonadMask m, MonadIO m) => RetryPolicy -> m a -> m a #

data DownloadRequest #

A request together with some checks to perform.

Constructors

DownloadRequest |
Fields drRequest :: Request drHashChecks :: [HashCheck] drLengthCheck :: Maybe LengthCheck drRetryPolicy :: RetryPolicy

drRetryPolicyDefault :: RetryPolicy #

Default to retrying thrice with a short constant delay.

data HashCheck #

Constructors

(Show a, HashAlgorithm a) => HashCheck |
Fields hashCheckAlgorithm :: a hashCheckHexDigest :: CheckHexDigest

Instances

Show HashCheck # |
Methods showsPrec :: Int -> HashCheck -> ShowS # show :: HashCheck -> String # showList :: [HashCheck] -> ShowS #

data CheckHexDigest #

Constructors

CheckHexDigestString String |
CheckHexDigestByteString ByteString |
CheckHexDigestHeader ByteString |

Instances

Show CheckHexDigest # |
Methods showsPrec :: Int -> CheckHexDigest -> ShowS # show :: CheckHexDigest -> String # showList :: [CheckHexDigest] -> ShowS #
IsString CheckHexDigest # |
Methods fromString :: String -> CheckHexDigest #

type LengthCheck = Int #

data VerifiedDownloadException #

An exception regarding verification of a download.

Constructors

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

Instances

Show VerifiedDownloadException # |
Methods showsPrec :: Int -> VerifiedDownloadException -> ShowS # show :: VerifiedDownloadException -> String # showList :: [VerifiedDownloadException] -> ShowS #
Exception VerifiedDownloadException # |
Methods toException :: VerifiedDownloadException -> SomeException # fromException :: SomeException -> Maybe VerifiedDownloadException # displayException :: VerifiedDownloadException -> String #