| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
Network.HTTP.Download
Synopsis
- verifiedDownload :: HasRunner env => DownloadRequest -> Path Abs File -> (Maybe Integer -> ConduitM ByteString Void (RIO env) ()) -> RIO env Bool
 - data DownloadRequest = DownloadRequest {}
 - drRetryPolicyDefault :: RetryPolicy
 - data HashCheck = (Show a, HashAlgorithm a) => HashCheck {}
 - data DownloadException
 - data CheckHexDigest
 - type LengthCheck = Int
 - data VerifiedDownloadException
 - download :: HasRunner env => Request -> Path Abs File -> RIO env Bool
 - redownload :: HasRunner env => Request -> Path Abs File -> RIO env Bool
 - httpJSON :: (MonadIO m, FromJSON a) => Request -> m (Response a)
 - httpLbs :: MonadIO m => Request -> m (Response ByteString)
 - httpLBS :: MonadIO m => Request -> m (Response ByteString)
 - parseRequest :: MonadThrow m => String -> m Request
 - parseUrlThrow :: MonadThrow m => String -> m Request
 - setGithubHeaders :: Request -> Request
 - withResponse :: (MonadUnliftIO m, MonadIO n) => Request -> (Response (ConduitM i ByteString n ()) -> m a) -> m a
 
Documentation
Arguments
| :: HasRunner 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.
data DownloadRequest Source #
A request together with some checks to perform.
Constructors
| DownloadRequest | |
Fields  | |
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
 
Constructors
| (Show a, HashAlgorithm a) => HashCheck | |
Fields  | |
data DownloadException Source #
Constructors
| RedownloadInvalidResponse Request (Path Abs File) (Response ()) | |
| RedownloadHttpError HttpException | 
Instances
| Show DownloadException Source # | |
Defined in Network.HTTP.Download Methods showsPrec :: Int -> DownloadException -> ShowS # show :: DownloadException -> String # showList :: [DownloadException] -> ShowS #  | |
| Exception DownloadException Source # | |
Defined in Network.HTTP.Download Methods toException :: DownloadException -> SomeException #  | |
data CheckHexDigest Source #
Constructors
| CheckHexDigestString String | |
| CheckHexDigestByteString ByteString | |
| CheckHexDigestHeader ByteString | 
Instances
| Show CheckHexDigest Source # | |
Defined in Network.HTTP.Download.Verified Methods showsPrec :: Int -> CheckHexDigest -> ShowS # show :: CheckHexDigest -> String # showList :: [CheckHexDigest] -> ShowS #  | |
| IsString CheckHexDigest Source # | |
Defined in Network.HTTP.Download.Verified Methods fromString :: String -> CheckHexDigest #  | |
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 | 
Instances
| Show VerifiedDownloadException Source # | |
Defined in Network.HTTP.Download.Verified Methods showsPrec :: Int -> VerifiedDownloadException -> ShowS # show :: VerifiedDownloadException -> String # showList :: [VerifiedDownloadException] -> ShowS #  | |
| Exception VerifiedDownloadException Source # | |
Defined in Network.HTTP.Download.Verified  | |
Arguments
| :: HasRunner 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
parseRequest :: MonadThrow m => String -> m Request #
Convert a URL into a Request.
This function defaults some of the values in Request, such as setting method to
 GET and requestHeaders to [].
Since this function uses MonadThrow, the return monad can be anything that is
 an instance of MonadThrow, such as IO or Maybe.
You can place the request method at the beginning of the URL separated by a space, e.g.:
@@
 parseRequest "POST http://httpbin.org/post"
 @@
Note that the request method must be provided as all capital letters.
A Request created by this function won't cause exceptions on non-2XX
 response status codes.
To create a request which throws on non-2XX status codes, see parseUrlThrow
Since: http-client-0.4.30
parseUrlThrow :: MonadThrow m => String -> m Request #
Same as parseRequest, except will throw an HttpException in the
 event of a non-2XX response. This uses throwErrorStatusCodes to
 implement checkResponse.
Since: http-client-0.4.30
setGithubHeaders :: Request -> Request Source #
Set the user-agent request header
withResponse :: (MonadUnliftIO m, MonadIO n) => Request -> (Response (ConduitM i ByteString n ()) -> m a) -> m a Source #