Safe Haskell | None |
---|---|
Language | Haskell2010 |
- verifiedDownload :: (MonadReader env m, HasHttpManager env, MonadIO m) => DownloadRequest -> Path Abs File -> (Maybe Integer -> Sink ByteString (ReaderT env IO) ()) -> m Bool
- data DownloadRequest = DownloadRequest {}
- drRetryPolicyDefault :: RetryPolicy
- data HashCheck = forall a . (Show a, HashAlgorithm a) => HashCheck {}
- data DownloadException
- data CheckHexDigest
- type LengthCheck = Int
- data VerifiedDownloadException
- download :: (MonadReader env m, HasHttpManager env, MonadIO m) => Request -> Path Abs File -> m Bool
- redownload :: (MonadReader env m, HasHttpManager env, MonadIO m) => Request -> Path Abs File -> m Bool
- downloadJSON :: (FromJSON a, MonadReader env m, HasHttpManager env, MonadIO m, MonadThrow m) => Request -> m a
- parseUrl :: MonadThrow m => String -> m Request
- liftHTTP :: (MonadIO m, MonadReader env m, HasHttpManager env) => ReaderT Manager IO a -> m a
- ask :: MonadReader r m => m r
- getHttpManager :: HasHttpManager a => a -> Manager
- class Monad m => MonadReader r m | m -> r where
- ask :: m r
- class HasHttpManager a where
- getHttpManager :: a -> Manager
Documentation
:: (MonadReader env m, HasHttpManager env, MonadIO m) | |
=> DownloadRequest | |
-> Path Abs File | destination |
-> (Maybe Integer -> Sink ByteString (ReaderT env 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.
data DownloadRequest Source
A request together with some checks to perform.
drRetryPolicyDefault :: RetryPolicy Source
Default to retrying thrice with a short constant delay.
forall a . (Show a, HashAlgorithm a) => HashCheck | |
data DownloadException Source
data CheckHexDigest Source
type LengthCheck = Int Source
data VerifiedDownloadException Source
An exception regarding verification of a download.
:: (MonadReader env m, HasHttpManager env, MonadIO m) | |
=> Request | |
-> Path Abs File | destination |
-> m 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
:: (MonadReader env m, HasHttpManager env, MonadIO m) | |
=> Request | |
-> Path Abs File | destination |
-> m Bool |
downloadJSON :: (FromJSON a, MonadReader env m, HasHttpManager env, MonadIO m, MonadThrow m) => Request -> m a Source
Download a JSON value and parse it using a FromJSON
instance.
parseUrl :: MonadThrow m => String -> m Request
Convert a URL into a Request
.
This 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
.
Since 0.1.0
liftHTTP :: (MonadIO m, MonadReader env m, HasHttpManager env) => ReaderT Manager IO a -> m a Source
A convenience method for asking for the environment and then running an
action with its Manager
. Useful for avoiding a MonadBaseControl
constraint.
ask :: MonadReader r m => m r
Retrieves the monad environment.
getHttpManager :: HasHttpManager a => a -> Manager
class Monad m => MonadReader r m | m -> r where
See examples in Control.Monad.Reader.
Note, the partially applied function type (->) r
is a simple reader monad.
See the instance
declaration below.
ask :: m r
Retrieves the monad environment.
class HasHttpManager a where
getHttpManager :: a -> Manager