hackage-security-0.6.2.6: Hackage security library

Safe Haskell | None
Language | Haskell2010

Hackage.Security.Client.Repository.HttpLib

Contents

- Body reader

Description

Abstracting over HTTP libraries

Synopsis

- data HttpLib = HttpLib {
  - httpGet :: forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> ([HttpResponseHeader] -> BodyReader -> IO a) -> IO a
  - httpGetRange :: forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> (Int, Int) -> (HttpStatus -> [HttpResponseHeader] -> BodyReader -> IO a) -> IO a
  }
- data HttpRequestHeader
  - = HttpRequestMaxAge0
  - | HttpRequestNoTransform
- data HttpResponseHeader = HttpResponseAcceptRangesBytes
- data HttpStatus
  - = HttpStatus200OK
  - | HttpStatus206PartialContent
- data ProxyConfig a
  - = ProxyConfigNone
  - | ProxyConfigUse a
  - | ProxyConfigAuto
- type BodyReader = IO ByteString
- bodyReaderFromBS :: ByteString -> IO BodyReader

# Documentation

data HttpLib #

Abstraction over HTTP clients

This avoids insisting on a particular implementation (such as the HTTP package) and allows for other implementations (such as a conduit based one).

NOTE: Library-specific exceptions MUST be wrapped in `SomeRemoteError`.

Constructors

HttpLib |
Fields httpGet :: forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> ([HttpResponseHeader] -> BodyReader -> IO a) -> IO a Download a file httpGetRange :: forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> (Int, Int) -> (HttpStatus -> [HttpResponseHeader] -> BodyReader -> IO a) -> IO a Download a byte range Range is starting and (exclusive) end offset in bytes. HTTP servers are normally expected to respond to a range request with a "206 Partial Content" response. However, servers can respond with a "200 OK" response, sending the entire file instead (for instance, this may happen for servers that don't actually support range requests, but for which we optimistically assumed they did). Implementations of `HttpLib` may accept such a response and inform the `hackage-security` library that the whole file is being returned; the security library can then decide to execute the `BodyReader` anyway (downloading the entire file) or abort the request and try something else. For this reason the security library must be informed whether the server returned the full file or the requested range.

data HttpRequestHeader #

Additional request headers

Since different libraries represent headers differently, here we just abstract over the few request headers that we might want to set

Constructors

HttpRequestMaxAge0 | Set `Cache-Control: max-age=0`
HttpRequestNoTransform | Set `Cache-Control: no-transform`

#### Instances

Instances details

Show HttpRequestHeader # |
Instance details Defined in Hackage.Security.Client.Repository.HttpLib Methods showsPrec :: Int -> HttpRequestHeader -> ShowS # show :: HttpRequestHeader -> String # showList :: [HttpRequestHeader] -> ShowS #
Eq HttpRequestHeader # |
Instance details Defined in Hackage.Security.Client.Repository.HttpLib Methods (==) :: HttpRequestHeader -> HttpRequestHeader -> Bool # (/=) :: HttpRequestHeader -> HttpRequestHeader -> Bool #
Ord HttpRequestHeader # |
Instance details Defined in Hackage.Security.Client.Repository.HttpLib Methods compare :: HttpRequestHeader -> HttpRequestHeader -> Ordering # (<) :: HttpRequestHeader -> HttpRequestHeader -> Bool # (<=) :: HttpRequestHeader -> HttpRequestHeader -> Bool # (>) :: HttpRequestHeader -> HttpRequestHeader -> Bool # (>=) :: HttpRequestHeader -> HttpRequestHeader -> Bool # max :: HttpRequestHeader -> HttpRequestHeader -> HttpRequestHeader # min :: HttpRequestHeader -> HttpRequestHeader -> HttpRequestHeader #

data HttpResponseHeader #

Response headers

Since different libraries represent headers differently, here we just abstract over the few response headers that we might want to know about.

Constructors

HttpResponseAcceptRangesBytes | Server accepts byte-range requests (`Accept-Ranges: bytes`)

#### Instances

Instances details

Show HttpResponseHeader # |
Instance details Defined in Hackage.Security.Client.Repository.HttpLib Methods showsPrec :: Int -> HttpResponseHeader -> ShowS # show :: HttpResponseHeader -> String # showList :: [HttpResponseHeader] -> ShowS #
Eq HttpResponseHeader # |
Instance details Defined in Hackage.Security.Client.Repository.HttpLib Methods (==) :: HttpResponseHeader -> HttpResponseHeader -> Bool # (/=) :: HttpResponseHeader -> HttpResponseHeader -> Bool #
Ord HttpResponseHeader # |
Instance details Defined in Hackage.Security.Client.Repository.HttpLib Methods compare :: HttpResponseHeader -> HttpResponseHeader -> Ordering # (<) :: HttpResponseHeader -> HttpResponseHeader -> Bool # (<=) :: HttpResponseHeader -> HttpResponseHeader -> Bool # (>) :: HttpResponseHeader -> HttpResponseHeader -> Bool # (>=) :: HttpResponseHeader -> HttpResponseHeader -> Bool # max :: HttpResponseHeader -> HttpResponseHeader -> HttpResponseHeader # min :: HttpResponseHeader -> HttpResponseHeader -> HttpResponseHeader #

data HttpStatus #

HTTP status code

Constructors

HttpStatus200OK | 200 OK
HttpStatus206PartialContent | 206 Partial Content

data ProxyConfig a #

Proxy configuration

Although actually setting the proxy is the purview of the initialization function for individual `HttpLib` implementations and therefore outside the scope of this module, we offer this `ProxyConfiguration` type here as a way to uniformly configure proxies across all `HttpLib`s.

Constructors

ProxyConfigNone | Don't use a proxy
ProxyConfigUse a | Use this specific proxy Individual HTTP backends use their own types for specifying proxies.
ProxyConfigAuto | Use automatic proxy settings What precisely automatic means is `HttpLib` specific, though typically it will involve looking at the `HTTP_PROXY` environment variable or the (Windows) registry.

## Body reader

type BodyReader = IO ByteString #

An `IO` action that represents an incoming response body coming from the server.

The action gets a single chunk of data from the response body, or an empty bytestring if no more data is available.

This definition is copied from the `http-client` package.

bodyReaderFromBS :: ByteString -> IO BodyReader #

Construct a `Body` reader from a lazy bytestring

This is appropriate if the lazy bytestring is constructed, say, by calling `hGetContents` on a network socket, and the chunks of the bytestring correspond to the chunks as they are returned from the OS network layer.

If the lazy bytestring needs to be re-chunked this function is NOT suitable.