http-conduit-2.3.9.1: HTTP client package with conduit interface and HTTPS support.

Safe Haskell | None
Language | Haskell2010

Network.HTTP.Client.Conduit

Contents

- Conduit-specific interface
- Manager helpers
- General HTTP client interface
- Lower-level conduit functions

Description

A new, experimental API to replace Network.HTTP.Conduit.

For most users, Network.HTTP.Simple is probably a better choice. For more information, see:

https://haskell-lang.org/library/http-client

For more information on using this module, please be sure to read the documentation in the Network.HTTP.Client module.

Synopsis

- withResponse :: forall m (n :: Type -> Type) env i a. (MonadUnliftIO m, MonadIO n, MonadReader env m, HasHttpManager env) => Request -> (Response (ConduitM i ByteString n ()) -> m a) -> m a
- responseOpen :: forall m (n :: Type -> Type) env i. (MonadIO m, MonadIO n, MonadReader env m, HasHttpManager env) => Request -> m (Response (ConduitM i ByteString n ()))
- responseClose :: MonadIO m => Response body -> m ()
- acquireResponse :: forall (n :: Type -> Type) env m i. (MonadIO n, MonadReader env m, HasHttpManager env) => Request -> m (Acquire (Response (ConduitM i ByteString n ())))
- httpSource :: forall (m :: Type -> Type) (n :: Type -> Type) env r. (MonadResource m, MonadIO n, MonadReader env m, HasHttpManager env) => Request -> (Response (ConduitM () ByteString n ()) -> ConduitM () r m ()) -> ConduitM () r m ()
- defaultManagerSettings :: ManagerSettings
- newManager :: MonadIO m => m Manager
- newManagerSettings :: MonadIO m => ManagerSettings -> m Manager
- data Proxy = Proxy {
  - proxyHost :: ByteString
  - proxyPort :: Int
  }
- data Request
- data StreamFileStatus = StreamFileStatus {
  - fileSize :: Int64
  - readSoFar :: Int64
  - thisChunkSize :: Int
  }
- class HasHttpManager a where
  - getHttpManager :: a -> Manager
- data Manager
- data ProxyOverride
- data ManagerSettings
- data Response body
- data ResponseTimeout
- data HttpExceptionContent
  - = StatusCodeException (Response ()) ByteString
  - | TooManyRedirects [Response ByteString]
  - | OverlongHeaders
  - | TooManyHeaderFields
  - | ResponseTimeout
  - | ConnectionTimeout
  - | ConnectionFailure SomeException
  - | InvalidStatusLine ByteString
  - | InvalidHeader ByteString
  - | InvalidRequestHeader ByteString
  - | InternalException SomeException
  - | ProxyConnectException ByteString Int Status
  - | NoResponseDataReceived
  - | TlsNotSupported
  - | WrongRequestBodyStreamSize Word64 Word64
  - | ResponseBodyTooShort Word64 Word64
  - | InvalidChunkHeaders
  - | IncompleteHeaders
  - | InvalidDestinationHost ByteString
  - | HttpZlibException ZlibException
  - | InvalidProxyEnvironmentVariable Text Text
  - | ConnectionClosed
  - | InvalidProxySettings Text
- type GivesPopper a = NeedsPopper a -> IO a
- type NeedsPopper a = Popper -> IO a
- type Popper = IO ByteString
- data RequestBody
  - = RequestBodyLBS ByteString
  - | RequestBodyBS ByteString
  - | RequestBodyBuilder Int64 Builder
  - | RequestBodyStream Int64 (GivesPopper ())
  - | RequestBodyStreamChunked (GivesPopper ())
  - | RequestBodyIO (IO RequestBody)
- data CookieJar
- data Cookie = Cookie {
  - cookie_name :: ByteString
  - cookie_value :: ByteString
  - cookie_expiry_time :: UTCTime
  - cookie_domain :: ByteString
  - cookie_path :: ByteString
  - cookie_creation_time :: UTCTime
  - cookie_last_access_time :: UTCTime
  - cookie_persistent :: Bool
  - cookie_host_only :: Bool
  - cookie_secure_only :: Bool
  - cookie_http_only :: Bool
  }
- data HttpException
  - = HttpExceptionRequest Request HttpExceptionContent
  - | InvalidUrlException String String
- equalCookie :: Cookie -> Cookie -> Bool
- equivCookie :: Cookie -> Cookie -> Bool
- compareCookies :: Cookie -> Cookie -> Ordering
- equalCookieJar :: CookieJar -> CookieJar -> Bool
- equivCookieJar :: CookieJar -> CookieJar -> Bool
- makeConnection :: IO ByteString -> (ByteString -> IO ()) -> IO () -> IO Connection
- socketConnection :: Socket -> Int -> IO Connection
- strippedHostName :: String -> String
- brReadSome :: BodyReader -> Int -> IO ByteString
- parseUrl :: MonadThrow m => String -> m Request
- parseUrlThrow :: MonadThrow m => String -> m Request
- throwErrorStatusCodes :: MonadIO m => Request -> Response BodyReader -> m ()
- parseRequest :: MonadThrow m => String -> m Request
- parseRequest_ :: String -> Request
- requestFromURI :: MonadThrow m => URI -> m Request
- requestFromURI_ :: URI -> Request
- getUri :: Request -> URI
- defaultRequest :: Request
- applyBasicAuth :: ByteString -> ByteString -> Request -> Request
- applyBearerAuth :: ByteString -> Request -> Request
- applyBasicProxyAuth :: ByteString -> ByteString -> Request -> Request
- urlEncodedBody :: [(ByteString, ByteString)] -> Request -> Request
- setRequestIgnoreStatus :: Request -> Request
- setRequestCheckStatus :: Request -> Request
- setQueryString :: [(ByteString, Maybe ByteString)] -> Request -> Request
- setQueryStringPartialEscape :: [(ByteString, [EscapeItem])] -> Request -> Request
- streamFile :: FilePath -> IO RequestBody
- observedStreamFile :: (StreamFileStatus -> IO ()) -> FilePath -> IO RequestBody
- getOriginalRequest :: Response a -> Request
- rawConnectionModifySocket :: (Socket -> IO ()) -> IO (Maybe HostAddress -> String -> Int -> IO Connection)
- rawConnectionModifySocketSize :: (Socket -> IO ()) -> IO (Int -> Maybe HostAddress -> String -> Int -> IO Connection)
- withManager :: ManagerSettings -> (Manager -> IO a) -> IO a
- proxyFromRequest :: ProxyOverride
- noProxy :: ProxyOverride
- useProxy :: Proxy -> ProxyOverride
- useProxySecureWithoutConnect :: Proxy -> ProxyOverride
- proxyEnvironment :: Maybe Proxy -> ProxyOverride
- proxyEnvironmentNamed :: Text -> Maybe Proxy -> ProxyOverride
- defaultProxy :: ProxyOverride
- isIpAddress :: ByteString -> Bool
- domainMatches :: ByteString -> ByteString -> Bool
- defaultPath :: Request -> ByteString
- pathMatches :: ByteString -> ByteString -> Bool
- createCookieJar :: [Cookie] -> CookieJar
- destroyCookieJar :: CookieJar -> [Cookie]
- removeExistingCookieFromCookieJar :: Cookie -> CookieJar -> (Maybe Cookie, CookieJar)
- isPotentiallyTrustworthyOrigin :: Bool -> ByteString -> Bool
- evictExpiredCookies :: CookieJar -> UTCTime -> CookieJar
- insertCookiesIntoRequest :: Request -> CookieJar -> UTCTime -> (Request, CookieJar)
- computeCookieString :: Request -> CookieJar -> UTCTime -> Bool -> (ByteString, CookieJar)
- updateCookieJar :: Response a -> Request -> UTCTime -> CookieJar -> (CookieJar, Response a)
- receiveSetCookie :: SetCookie -> Request -> UTCTime -> Bool -> CookieJar -> CookieJar
- insertCheckedCookie :: Cookie -> CookieJar -> Bool -> CookieJar
- generateCookie :: SetCookie -> Request -> UTCTime -> Bool -> Maybe Cookie
- withConnection :: Request -> Manager -> (Connection -> IO a) -> IO a
- data HistoriedResponse body
- responseOpenHistory :: Request -> Manager -> IO (HistoriedResponse BodyReader)
- withResponseHistory :: Request -> Manager -> (HistoriedResponse BodyReader -> IO a) -> IO a
- managerSetInsecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
- managerSetSecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
- managerSetProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
- managerSetMaxHeaderLength :: Int -> ManagerSettings -> ManagerSettings
- managerSetMaxNumberHeaders :: Int -> ManagerSettings -> ManagerSettings
- responseTimeoutMicro :: Int -> ResponseTimeout
- responseTimeoutNone :: ResponseTimeout
- responseTimeoutDefault :: ResponseTimeout
- httpLbs :: (MonadIO m, HasHttpManager env, MonadReader env m) => Request -> m (Response ByteString)
- httpNoBody :: (MonadIO m, HasHttpManager env, MonadReader env m) => Request -> m (Response ())
- requestBodySource :: Int64 -> ConduitM () ByteString IO () -> RequestBody
- requestBodySourceChunked :: ConduitM () ByteString IO () -> RequestBody
- bodyReaderSource :: forall (m :: Type -> Type) i. MonadIO m => BodyReader -> ConduitM i ByteString m ()

# Conduit-specific interface

withResponse :: forall m (n :: Type -> Type) env i a. (MonadUnliftIO m, MonadIO n, MonadReader env m, HasHttpManager env) => Request -> (Response (ConduitM i ByteString n ()) -> m a) -> m a Source #

Conduit powered version of `withResponse`. Differences are:

- Response body is represented as a `Producer`.
- Generalized to any instance of `MonadUnliftIO`, not just `IO`.
- The `Manager` is contained by a `MonadReader` context.

Since 2.1.0

responseOpen :: forall m (n :: Type -> Type) env i. (MonadIO m, MonadIO n, MonadReader env m, HasHttpManager env) => Request -> m (Response (ConduitM i ByteString n ())) Source #

Conduit-powered version of `responseOpen`.

See `withResponse` for the differences with `responseOpen`.

Since 2.1.0

responseClose :: MonadIO m => Response body -> m () Source #

Generalized version of `responseClose`.

Since 2.1.0

acquireResponse :: forall (n :: Type -> Type) env m i. (MonadIO n, MonadReader env m, HasHttpManager env) => Request -> m (Acquire (Response (ConduitM i ByteString n ()))) Source #

An `Acquire` for getting a `Response`.

Since 2.1.0

httpSource :: forall (m :: Type -> Type) (n :: Type -> Type) env r. (MonadResource m, MonadIO n, MonadReader env m, HasHttpManager env) => Request -> (Response (ConduitM () ByteString n ()) -> ConduitM () r m ()) -> ConduitM () r m () Source #

Same as `httpSource`, but uses `Manager` from Reader environment instead of the global one.

Since 2.3.6

# Manager helpers

defaultManagerSettings :: ManagerSettings Source #

TLS-powered manager settings.

Since 2.1.0

newManager :: MonadIO m => m Manager Source #

Get a new manager using `defaultManagerSettings`.

Since 2.1.0

newManagerSettings :: MonadIO m => ManagerSettings -> m Manager Source #

Get a new manager using the given settings.

Since 2.1.0

# General HTTP client interface

data Proxy Source #

Define a HTTP proxy, consisting of a hostname and port number.

Constructors

Proxy |

Fields

- proxyHost :: ByteString

  The host name of the HTTP proxy in URI format. IPv6 addresses in square brackets.

- proxyPort :: Int

  The port number of the HTTP proxy.

#### Instances

Instances details

Read Proxy |
Instance details Defined in Network.HTTP.Client.Types Methods readsPrec :: Int -> ReadS Proxy Source # readList :: ReadS [Proxy] Source # readPrec :: ReadPrec Proxy Source # readListPrec :: ReadPrec [Proxy] Source #
Show Proxy |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> Proxy -> ShowS Source # show :: Proxy -> String Source # showList :: [Proxy] -> ShowS Source #
Eq Proxy |
Instance details Defined in Network.HTTP.Client.Types Methods (==) :: Proxy -> Proxy -> Bool Source # (/=) :: Proxy -> Proxy -> Bool Source #
Ord Proxy |
Instance details Defined in Network.HTTP.Client.Types Methods compare :: Proxy -> Proxy -> Ordering Source # (<) :: Proxy -> Proxy -> Bool Source # (<=) :: Proxy -> Proxy -> Bool Source # (>) :: Proxy -> Proxy -> Bool Source # (>=) :: Proxy -> Proxy -> Bool Source # max :: Proxy -> Proxy -> Proxy Source # min :: Proxy -> Proxy -> Proxy Source #

data Request Source #

All information on how to connect to a host and what should be sent in the HTTP request.

If you simply wish to download from a URL, see `parseRequest`.

The constructor for this data type is not exposed. Instead, you should use either the `defaultRequest` value, or `parseRequest` to construct from a URL, and then use the records below to make modifications. This approach allows http-client to add configuration options without breaking backwards compatibility.

For example, to construct a POST request, you could do something like:

    initReq <- parseRequest "http://www.example.com/path"
    let req = initReq
                { method = "POST"
                }

For more information, please see http://www.yesodweb.com/book/settings-types.

Since 0.1.0

#### Instances

Instances details

IsString Request | Parses a URL via `parseRequest_` NOTE: Prior to version 0.5.0, this instance used `parseUrlThrow` instead.
Instance details Defined in Network.HTTP.Client.Request Methods fromString :: String -> Request Source #
Show Request |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> Request -> ShowS Source # show :: Request -> String Source # showList :: [Request] -> ShowS Source #

data StreamFileStatus Source #

Status of streaming a request body from a file.

Since 0.4.9

Constructors

StreamFileStatus |

Fields

- fileSize :: Int64
- readSoFar :: Int64
- thisChunkSize :: Int

#### Instances

Instances details

Show StreamFileStatus |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> StreamFileStatus -> ShowS Source # show :: StreamFileStatus -> String Source # showList :: [StreamFileStatus] -> ShowS Source #
Eq StreamFileStatus |
Instance details Defined in Network.HTTP.Client.Types Methods (==) :: StreamFileStatus -> StreamFileStatus -> Bool Source # (/=) :: StreamFileStatus -> StreamFileStatus -> Bool Source #
Ord StreamFileStatus |

Instance details

Defined in Network.HTTP.Client.Types

Methods

compare :: StreamFileStatus -> StreamFileStatus -> Ordering Source #

(<) :: StreamFileStatus -> StreamFileStatus -> Bool Source #

(<=) :: StreamFileStatus -> StreamFileStatus -> Bool Source #

(>) :: StreamFileStatus -> StreamFileStatus -> Bool Source #

(>=) :: StreamFileStatus -> StreamFileStatus -> Bool Source #

max :: StreamFileStatus -> StreamFileStatus -> StreamFileStatus Source #

min :: StreamFileStatus -> StreamFileStatus -> StreamFileStatus Source #

class HasHttpManager a where Source #

Methods

getHttpManager :: a -> Manager Source #

#### Instances

Instances details

HasHttpManager Manager |
Instance details Defined in Network.HTTP.Client.Types Methods getHttpManager :: Manager -> Manager Source #

data Manager Source #

Keeps track of open connections for keep-alive.

If possible, you should share a single `Manager` between multiple threads and requests.

Since 0.1.0

#### Instances

Instances details

HasHttpManager Manager |
Instance details Defined in Network.HTTP.Client.Types Methods getHttpManager :: Manager -> Manager Source #

data ProxyOverride Source #

How the HTTP proxy server settings should be discovered.

Since 0.4.7

data ManagerSettings Source #

Settings for a `Manager`. Please use the `defaultManagerSettings` function and then modify individual settings. For more information, see http://www.yesodweb.com/book/settings-types.

Since 0.1.0

data Response body Source #

A simple representation of the HTTP response.

Since 0.1.0

#### Instances

Instances details

Functor Response |
Instance details Defined in Network.HTTP.Client.Types Methods fmap :: (a -> b) -> Response a -> Response b Source # (<$) :: a -> Response b -> Response a Source #
Foldable Response |

Instance details

Defined in Network.HTTP.Client.Types

Methods

fold :: Monoid m => Response m -> m Source #

foldMap :: Monoid m => (a -> m) -> Response a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Response a -> m Source #

foldr :: (a -> b -> b) -> b -> Response a -> b Source #

foldr' :: (a -> b -> b) -> b -> Response a -> b Source #

foldl :: (b -> a -> b) -> b -> Response a -> b Source #

foldl' :: (b -> a -> b) -> b -> Response a -> b Source #

foldr1 :: (a -> a -> a) -> Response a -> a Source #

foldl1 :: (a -> a -> a) -> Response a -> a Source #

toList :: Response a -> [a] Source #

null :: Response a -> Bool Source #

length :: Response a -> Int Source #

elem :: Eq a => a -> Response a -> Bool Source #

maximum :: Ord a => Response a -> a Source #

minimum :: Ord a => Response a -> a Source #

sum :: Num a => Response a -> a Source #

product :: Num a => Response a -> a Source #

Traversable Response |
Instance details Defined in Network.HTTP.Client.Types Methods traverse :: Applicative f => (a -> f b) -> Response a -> f (Response b) Source # sequenceA :: Applicative f => Response (f a) -> f (Response a) Source # mapM :: Monad m => (a -> m b) -> Response a -> m (Response b) Source # sequence :: Monad m => Response (m a) -> m (Response a) Source #
Show body => Show (Response body) |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> Response body -> ShowS Source # show :: Response body -> String Source # showList :: [Response body] -> ShowS Source #

data ResponseTimeout Source #

How to deal with timing out on retrieval of response headers.

Since: http-client-0.5.0

#### Instances

Instances details

Show ResponseTimeout |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> ResponseTimeout -> ShowS Source # show :: ResponseTimeout -> String Source # showList :: [ResponseTimeout] -> ShowS Source #
Eq ResponseTimeout |
Instance details Defined in Network.HTTP.Client.Types Methods (==) :: ResponseTimeout -> ResponseTimeout -> Bool Source # (/=) :: ResponseTimeout -> ResponseTimeout -> Bool Source #

data HttpExceptionContent Source #

Constructors

StatusCodeException (Response ()) ByteString | Generated by the `parseUrlThrow` function when the server returns a non-2XX response status code. May include the beginning of the response body. Since: http-client-0.5.0
TooManyRedirects [Response ByteString] | The server responded with too many redirects for a request. Contains the list of encountered responses containing redirects in reverse chronological order; including last redirect, which triggered the exception and was not followed. Since: http-client-0.5.0
OverlongHeaders | Too many total bytes in the HTTP header were returned by the server. Since: http-client-0.5.0
TooManyHeaderFields | Too many HTTP header fields were returned by the server. Since: http-client-0.7.18
ResponseTimeout | The server took too long to return a response. This can be altered via `responseTimeout` or `managerResponseTimeout`. Since: http-client-0.5.0
ConnectionTimeout | Attempting to connect to the server timed out. Since: http-client-0.5.0
ConnectionFailure SomeException | An exception occurred when trying to connect to the server. Since: http-client-0.5.0
InvalidStatusLine ByteString | The status line returned by the server could not be parsed. Since: http-client-0.5.0
InvalidHeader ByteString | The given response header line could not be parsed Since: http-client-0.5.0
InvalidRequestHeader ByteString | The given request header is not compliant (e.g. has newlines) Since: http-client-0.5.14
InternalException SomeException | An exception was raised by an underlying library when performing the request. Most often, this is caused by a failing socket action or a TLS exception. Since: http-client-0.5.0
ProxyConnectException ByteString Int Status | A non-200 status code was returned when trying to connect to the proxy server on the given host and port. Since: http-client-0.5.0
NoResponseDataReceived | No response data was received from the server at all. This exception may deserve special handling within the library, since it may indicate that a pipelining has been used, and a connection thought to be open was in fact closed. Since: http-client-0.5.0
TlsNotSupported | Exception thrown when using a `Manager` which does not have support for secure connections. Typically, you will want to use `tlsManagerSettings` from `http-client-tls` to overcome this. Since: http-client-0.5.0
WrongRequestBodyStreamSize Word64 Word64 | The request body provided did not match the expected size. Provides the expected and actual size. Since: http-client-0.4.31
ResponseBodyTooShort Word64 Word64 | The returned response body is too short. Provides the expected size and actual size. Since: http-client-0.5.0
InvalidChunkHeaders | A chunked response body had invalid headers. Since: http-client-0.5.0
IncompleteHeaders | An incomplete set of response headers were returned. Since: http-client-0.5.0
InvalidDestinationHost ByteString | The host we tried to connect to is invalid (e.g., an empty string).
HttpZlibException ZlibException | An exception was thrown when inflating a response body. Since: http-client-0.5.0
InvalidProxyEnvironmentVariable Text Text | Values in the proxy environment variable were invalid. Provides the environment variable name and its value. Since: http-client-0.5.0
ConnectionClosed | Attempted to use a `Connection` which was already closed Since: http-client-0.5.0
InvalidProxySettings Text | Proxy settings are not valid (Windows specific currently) @since 0.5.7

#### Instances

Instances details

Show HttpExceptionContent |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> HttpExceptionContent -> ShowS Source # show :: HttpExceptionContent -> String Source # showList :: [HttpExceptionContent] -> ShowS Source #

type GivesPopper a = NeedsPopper a -> IO a Source #

A function which will provide a `Popper` to a `NeedsPopper`. This seemingly convoluted structure allows for creation of request bodies which allocate scarce resources in an exception safe manner.

Since 0.1.0

type NeedsPopper a = Popper -> IO a Source #

A function which must be provided with a `Popper`.

Since 0.1.0

type Popper = IO ByteString Source #

A function which generates successive chunks of a request body, provider a single empty bytestring when no more data is available.

Since 0.1.0

data RequestBody Source #

When using one of the `RequestBodyStream` / `RequestBodyStreamChunked` constructors, you must ensure that the `GivesPopper` can be called multiple times. Usually this is not a problem.

The `RequestBodyStreamChunked` will send a chunked request body. Note that not all servers support this. Only use `RequestBodyStreamChunked` if you know the server you're sending to supports chunked request bodies.

Since 0.1.0

Constructors

RequestBodyLBS ByteString |
RequestBodyBS ByteString |
RequestBodyBuilder Int64 Builder |
RequestBodyStream Int64 (GivesPopper ()) |
RequestBodyStreamChunked (GivesPopper ()) |
RequestBodyIO (IO RequestBody) | Allows creation of a `RequestBody` inside the `IO` monad, which is useful for making easier APIs (like `setRequestBodyFile`). Since: http-client-0.4.28

#### Instances

Instances details

Monoid RequestBody |
Instance details Defined in Network.HTTP.Client.Types Methods mempty :: RequestBody Source # mappend :: RequestBody -> RequestBody -> RequestBody Source # mconcat :: [RequestBody] -> RequestBody Source #
Semigroup RequestBody |
Instance details Defined in Network.HTTP.Client.Types Methods (<>) :: RequestBody -> RequestBody -> RequestBody Source # sconcat :: NonEmpty RequestBody -> RequestBody Source # stimes :: Integral b => b -> RequestBody -> RequestBody Source #
IsString RequestBody | Since 0.4.12
Instance details Defined in Network.HTTP.Client.Types Methods fromString :: String -> RequestBody Source #

data CookieJar Source #

#### Instances

Instances details

Monoid CookieJar | Since 1.9
Instance details Defined in Network.HTTP.Client.Types Methods mempty :: CookieJar Source # mappend :: CookieJar -> CookieJar -> CookieJar Source # mconcat :: [CookieJar] -> CookieJar Source #
Semigroup CookieJar |
Instance details Defined in Network.HTTP.Client.Types Methods (<>) :: CookieJar -> CookieJar -> CookieJar Source # sconcat :: NonEmpty CookieJar -> CookieJar Source # stimes :: Integral b => b -> CookieJar -> CookieJar Source #
Read CookieJar |
Instance details Defined in Network.HTTP.Client.Types Methods readsPrec :: Int -> ReadS CookieJar Source # readList :: ReadS [CookieJar] Source # readPrec :: ReadPrec CookieJar Source # readListPrec :: ReadPrec [CookieJar] Source #
Show CookieJar |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> CookieJar -> ShowS Source # show :: CookieJar -> String Source # showList :: [CookieJar] -> ShowS Source #

data Cookie Source #

Constructors

Cookie |

Fields

- cookie_name :: ByteString
- cookie_value :: ByteString
- cookie_expiry_time :: UTCTime
- cookie_domain :: ByteString
- cookie_path :: ByteString
- cookie_creation_time :: UTCTime
- cookie_last_access_time :: UTCTime
- cookie_persistent :: Bool
- cookie_host_only :: Bool
- cookie_secure_only :: Bool
- cookie_http_only :: Bool

#### Instances

Instances details

Read Cookie |
Instance details Defined in Network.HTTP.Client.Types Methods readsPrec :: Int -> ReadS Cookie Source # readList :: ReadS [Cookie] Source # readPrec :: ReadPrec Cookie Source # readListPrec :: ReadPrec [Cookie] Source #
Show Cookie |
Instance details Defined in Network.HTTP.Client.Types Methods showsPrec :: Int -> Cookie -> ShowS Source # show :: Cookie -> String Source # showList :: [Cookie] -> ShowS Source #

data HttpException Source #

An exception which may be generated by this library

Since: http-client-0.5.0

Constructors

HttpExceptionRequest Request HttpExceptionContent | Most exceptions are specific to a `Request`. Inspect the `HttpExceptionContent` value for details on what occurred. Since: http-client-0.5.0
InvalidUrlException String String | A URL (first field) is invalid for a given reason (second argument). Since: http-client-0.5.0

#### Instances

Instances details

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

equalCookie :: Cookie -> Cookie -> Bool Source #

Instead of `(==)`.

Since there was some confusion in the history of this library about how the `Eq` instance should work, it was removed for clarity, and replaced by `equal` and `equiv`. `equal` gives you equality of all fields of the `Cookie` record.

Since: http-client-0.7.0

equivCookie :: Cookie -> Cookie -> Bool Source #

Equality of name, domain, path only. This corresponds to step 11 of the algorithm described in Section 5.3 "Storage Model". See also: `equal`.

Since: http-client-0.7.0

compareCookies :: Cookie -> Cookie -> Ordering Source #

Instead of `instance Ord Cookie`. See `equalCookie`, `equivCookie`.

Since: http-client-0.7.0

equalCookieJar :: CookieJar -> CookieJar -> Bool Source #

See `equalCookie`.

Since: http-client-0.7.0

equivCookieJar :: CookieJar -> CookieJar -> Bool Source #

See `equalCookieJar`, `equalCookie`.

Since: http-client-0.7.0

makeConnection Source #

Arguments

:: IO ByteString | read
-> (ByteString -> IO ()) | write
-> IO () | close
-> IO Connection |

Create a new `Connection` from a read, write, and close function.

Since: http-client-0.5.3

socketConnection Source #

Arguments

:: Socket |
-> Int | chunk size
-> IO Connection |

Create a new `Connection` from a `Socket`.

Since: http-client-0.5.3

strippedHostName :: String -> String Source #

strippedHostName takes a URI host name, as extracted by `regName`, and strips square brackets around IPv6 addresses.

The result is suitable for passing to services such as name resolution (`getAddr`).

@since

brReadSome :: BodyReader -> Int -> IO ByteString Source #

Continuously call `brRead`, building up a lazy ByteString until a chunk is constructed that is at least as many bytes as requested.

Since 0.4.20

parseUrl :: MonadThrow m => String -> m Request Source #

Deprecated synonym for `parseUrlThrow`. You probably want `parseRequest` or `parseRequest_` instead.

Since: http-client-0.1.0

parseUrlThrow :: MonadThrow m => String -> m Request Source #

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

throwErrorStatusCodes :: MonadIO m => Request -> Response BodyReader -> m () Source #

Throws a `StatusCodeException` wrapped in `HttpExceptionRequest`, if the response's status code indicates an error (if it isn't 2xx). This can be used to implement `checkResponse`.

Since: http-client-0.5.13

parseRequest :: MonadThrow m => String -> m Request Source #

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

parseRequest_ :: String -> Request Source #

Same as `parseRequest`, but parse errors cause an impure exception. Mostly useful for static strings which are known to be correctly formatted.

requestFromURI :: MonadThrow m => URI -> m Request Source #

Convert a `URI` into a `Request`.

This can fail if the given `URI` is not absolute, or if the `URI` scheme is not `"http"` or `"https"`. In these cases the function will throw an error via `MonadThrow`.

This function defaults some of the values in `Request`, such as setting `method` to `GET` and `requestHeaders` to `[]`.

A `Request` created by this function won't cause exceptions on non-2XX response status codes.

Since: http-client-0.5.12

requestFromURI_ :: URI -> Request Source #

Same as `requestFromURI`, but if the conversion would fail, throws an impure exception.

Since: http-client-0.5.12

getUri :: Request -> URI Source #

Extract a `URI` from the request.

Since 0.1.0

defaultRequest :: Request Source #

A default request value, a GET request of localhost/:80, with an empty request body.

Note that the default `checkResponse` does nothing.

Since: http-client-0.4.30

applyBasicAuth :: ByteString -> ByteString -> Request -> Request Source #

Add a Basic Auth header (with the specified user name and password) to the given Request. Ignore error handling:

     applyBasicAuth "user" "pass" $ parseRequest_ url

NOTE: The function `applyDigestAuth` is provided by the `http-client-tls` package instead of this package due to extra dependencies. Please use that package if you need to use digest authentication.

Since 0.1.0

applyBearerAuth :: ByteString -> Request -> Request Source #

Add a Bearer Auth header to the given `Request`

Since: http-client-0.7.6

applyBasicProxyAuth :: ByteString -> ByteString -> Request -> Request Source #

Add a Proxy-Authorization header (with the specified username and password) to the given `Request`. Ignore error handling:

    applyBasicProxyAuth "user" "pass" <$> parseRequest "http://example.org"

Since 0.3.4

urlEncodedBody :: [(ByteString, ByteString)] -> Request -> Request Source #

Add url-encoded parameters to the `Request`.

This sets a new `requestBody`, adds a content-type request header and changes the `method` to POST.

Since 0.1.0

setRequestIgnoreStatus :: Request -> Request Source #

Modify the request so that non-2XX status codes do not generate a runtime `StatusCodeException`.

Since: http-client-0.4.29

setRequestCheckStatus :: Request -> Request Source #

Modify the request so that non-2XX status codes generate a runtime `StatusCodeException`, by using `throwErrorStatusCodes`

Since: http-client-0.5.13

setQueryString :: [(ByteString, Maybe ByteString)] -> Request -> Request Source #

Set the query string to the given key/value pairs.

Since 0.3.6

setQueryStringPartialEscape :: [(ByteString, [EscapeItem])] -> Request -> Request Source #

Set the query string to the given key/value pairs.

Since: http-client-0.5.10

streamFile :: FilePath -> IO RequestBody Source #

Send a file as the request body.

It is expected that the file size does not change between calling `streamFile` and making any requests using this request body.

Since 0.4.9

observedStreamFile :: (StreamFileStatus -> IO ()) -> FilePath -> IO RequestBody Source #

Send a file as the request body, while observing streaming progress via a `PopObserver`. Observations are made between reading and sending a chunk.

It is expected that the file size does not change between calling `observedStreamFile` and making any requests using this request body.

Since 0.4.9

getOriginalRequest :: Response a -> Request Source #

Retrieve the orignal `Request` from a `Response`

Note that the `requestBody` is not available and always set to empty.

Since: http-client-0.7.8

rawConnectionModifySocket :: (Socket -> IO ()) -> IO (Maybe HostAddress -> String -> Int -> IO Connection) Source #

A value for the `managerRawConnection` setting, but also allows you to modify the underlying `Socket` to set additional settings. For a motivating use case, see: https://github.com/snoyberg/http-client/issues/71.

Since 0.3.8

rawConnectionModifySocketSize :: (Socket -> IO ()) -> IO (Int -> Maybe HostAddress -> String -> Int -> IO Connection) Source #

Same as `rawConnectionModifySocket`, but also takes in a chunk size.

Since: http-client-0.5.2

withManager :: ManagerSettings -> (Manager -> IO a) -> IO a Source #

Create, use and close a `Manager`.

Since 0.2.1

proxyFromRequest :: ProxyOverride Source #

Get the proxy settings from the `Request` itself.

Since 0.4.7

noProxy :: ProxyOverride Source #

Never connect using a proxy, regardless of the proxy value in the `Request`.

Since 0.4.7

useProxy :: Proxy -> ProxyOverride Source #

Use the given proxy settings, regardless of the proxy value in the `Request`.

Since 0.4.7

useProxySecureWithoutConnect :: Proxy -> ProxyOverride Source #

Send secure requests to the proxy in plain text rather than using CONNECT, regardless of the value in the `Request`.

Since: http-client-0.7.2

proxyEnvironment Source #

Arguments

:: Maybe Proxy | fallback if no environment set
-> ProxyOverride |

Get the proxy settings from the default environment variable (`http_proxy` for insecure, `https_proxy` for secure). If no variable is set, then fall back to the given value. `Nothing` is equivalent to `noProxy`, `Just` is equivalent to `useProxy`.

Since 0.4.7

proxyEnvironmentNamed Source #

Arguments

:: Text | environment variable name
-> Maybe Proxy | fallback if no environment set
-> ProxyOverride |

Same as `proxyEnvironment`, but instead of default environment variable names, allows you to set your own name.

Since 0.4.7

defaultProxy :: ProxyOverride Source #

The default proxy settings for a manager. In particular: if the `http_proxy` (or `https_proxy`) environment variable is set, use it. Otherwise, use the values in the `Request`.

Since 0.4.7

isIpAddress :: ByteString -> Bool Source #

domainMatches Source #

Arguments

:: ByteString | Domain to test
-> ByteString | Domain from a cookie
-> Bool |

This corresponds to the subcomponent algorithm entitled "Domain Matching" detailed in section 5.1.3

defaultPath :: Request -> ByteString Source #

This corresponds to the subcomponent algorithm entitled "Paths" detailed in section 5.1.4

pathMatches :: ByteString -> ByteString -> Bool Source #

This corresponds to the subcomponent algorithm entitled "Path-Match" detailed in section 5.1.4

createCookieJar :: [Cookie] -> CookieJar Source #

destroyCookieJar :: CookieJar -> [Cookie] Source #

removeExistingCookieFromCookieJar :: Cookie -> CookieJar -> (Maybe Cookie, CookieJar) Source #

isPotentiallyTrustworthyOrigin Source #

Arguments

:: Bool | True if HTTPS
-> ByteString | Host
-> Bool | Whether or not the origin is potentially trustworthy

Algorithm described in "Secure Contexts", Section 3.1, "Is origin potentially trustworthy?"

Note per RFC6265 section 5.4 user agent is free to define the meaning of "secure" protocol.

See: https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy

evictExpiredCookies Source #

Arguments

:: CookieJar | Input cookie jar
-> UTCTime | Value that should be used as "now"
-> CookieJar | Filtered cookie jar

This corresponds to the eviction algorithm described in Section 5.3 "Storage Model"

insertCookiesIntoRequest Source #

Arguments

:: Request | The request to insert into
-> CookieJar | Current cookie jar
-> UTCTime | Value that should be used as "now"
-> (Request, CookieJar) | (Output request, Updated cookie jar (last-access-time is updated))

This applies the `computeCookieString` to a given Request

computeCookieString Source #

Arguments

:: Request | Input request
-> CookieJar | Current cookie jar
-> UTCTime | Value that should be used as "now"
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that)
-> (ByteString, CookieJar) | (Contents of a "Cookie" header, Updated cookie jar (last-access-time is updated))

This corresponds to the algorithm described in Section 5.4 "The Cookie Header"

updateCookieJar Source #

Arguments

:: Response a | Response received from server
-> Request | Request which generated the response
-> UTCTime | Value that should be used as "now"
-> CookieJar | Current cookie jar
-> (CookieJar, Response a) | (Updated cookie jar with cookies from the Response, The response stripped of any "Set-Cookie" header)

This applies `receiveSetCookie` to a given Response

receiveSetCookie Source #

Arguments

:: SetCookie | The `SetCookie` the cookie jar is receiving
-> Request | The request that originated the response that yielded the `SetCookie`
-> UTCTime | Value that should be used as "now"
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that)
-> CookieJar | Input cookie jar to modify
-> CookieJar | Updated cookie jar

This corresponds to the algorithm described in Section 5.3 "Storage Model" This function consists of calling `generateCookie` followed by `insertCheckedCookie`. Use this function if you plan to do both in a row. `generateCookie` and `insertCheckedCookie` are only provided for more fine-grained control.

insertCheckedCookie Source #

Arguments

:: Cookie | The `SetCookie` the cookie jar is receiving
-> CookieJar | Input cookie jar to modify
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that)
-> CookieJar | Updated (or not) cookie jar

Insert a cookie created by generateCookie into the cookie jar (or not if it shouldn't be allowed in)

generateCookie Source #

Arguments

:: SetCookie | The `SetCookie` we are encountering
-> Request | The request that originated the response that yielded the `SetCookie`
-> UTCTime | Value that should be used as "now"
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that)
-> Maybe Cookie | The optional output cookie

Turn a SetCookie into a Cookie, if it is valid

withConnection :: Request -> Manager -> (Connection -> IO a) -> IO a Source #

Perform an action using a `Connection` acquired from the given `Manager`.

You should use this only when you have to read and write interactively through the connection (e.g. connection by the WebSocket protocol).

Since: http-client-0.5.13

data HistoriedResponse body Source #

A datatype holding information on redirected requests and the final response.

Since 0.4.1

#### Instances

Instances details

Functor HistoriedResponse |
Instance details Defined in Network.HTTP.Client Methods fmap :: (a -> b) -> HistoriedResponse a -> HistoriedResponse b Source # (<$) :: a -> HistoriedResponse b -> HistoriedResponse a Source #
Foldable HistoriedResponse |

Instance details

Defined in Network.HTTP.Client

Methods

fold :: Monoid m => HistoriedResponse m -> m Source #

foldMap :: Monoid m => (a -> m) -> HistoriedResponse a -> m Source #

foldMap' :: Monoid m => (a -> m) -> HistoriedResponse a -> m Source #

foldr :: (a -> b -> b) -> b -> HistoriedResponse a -> b Source #

foldr' :: (a -> b -> b) -> b -> HistoriedResponse a -> b Source #

foldl :: (b -> a -> b) -> b -> HistoriedResponse a -> b Source #

foldl' :: (b -> a -> b) -> b -> HistoriedResponse a -> b Source #

foldr1 :: (a -> a -> a) -> HistoriedResponse a -> a Source #

foldl1 :: (a -> a -> a) -> HistoriedResponse a -> a Source #

toList :: HistoriedResponse a -> [a] Source #

null :: HistoriedResponse a -> Bool Source #

length :: HistoriedResponse a -> Int Source #

elem :: Eq a => a -> HistoriedResponse a -> Bool Source #

maximum :: Ord a => HistoriedResponse a -> a Source #

minimum :: Ord a => HistoriedResponse a -> a Source #

sum :: Num a => HistoriedResponse a -> a Source #

product :: Num a => HistoriedResponse a -> a Source #

Traversable HistoriedResponse |

Instance details

Defined in Network.HTTP.Client

Methods

traverse :: Applicative f => (a -> f b) -> HistoriedResponse a -> f (HistoriedResponse b) Source #

sequenceA :: Applicative f => HistoriedResponse (f a) -> f (HistoriedResponse a) Source #

mapM :: Monad m => (a -> m b) -> HistoriedResponse a -> m (HistoriedResponse b) Source #

sequence :: Monad m => HistoriedResponse (m a) -> m (HistoriedResponse a) Source #

Generic (HistoriedResponse body) |

Instance details

Defined in Network.HTTP.Client

Associated Types

type Rep (HistoriedResponse body) |

Instance details

Defined in Network.HTTP.Client

type Rep (HistoriedResponse body) = D1 ('MetaData "HistoriedResponse" "Network.HTTP.Client" "http-client-0.7.19-CKCO2uxM4gv2WYcBEj2FOG" 'False) (C1 ('MetaCons "HistoriedResponse" 'PrefixI 'True) (S1 ('MetaSel ('Just "hrRedirects") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Request, Response ByteString)]) :*: (S1 ('MetaSel ('Just "hrFinalRequest") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Request) :*: S1 ('MetaSel ('Just "hrFinalResponse") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Response body)))))

Methods

from :: HistoriedResponse body -> Rep (HistoriedResponse body) x Source #

to :: Rep (HistoriedResponse body) x -> HistoriedResponse body Source #

Show body => Show (HistoriedResponse body) |
Instance details Defined in Network.HTTP.Client Methods showsPrec :: Int -> HistoriedResponse body -> ShowS Source # show :: HistoriedResponse body -> String Source # showList :: [HistoriedResponse body] -> ShowS Source #
type Rep (HistoriedResponse body) |

Instance details

Defined in Network.HTTP.Client

type Rep (HistoriedResponse body) = D1 ('MetaData "HistoriedResponse" "Network.HTTP.Client" "http-client-0.7.19-CKCO2uxM4gv2WYcBEj2FOG" 'False) (C1 ('MetaCons "HistoriedResponse" 'PrefixI 'True) (S1 ('MetaSel ('Just "hrRedirects") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Request, Response ByteString)]) :*: (S1 ('MetaSel ('Just "hrFinalRequest") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Request) :*: S1 ('MetaSel ('Just "hrFinalResponse") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Response body)))))

responseOpenHistory :: Request -> Manager -> IO (HistoriedResponse BodyReader) Source #

A variant of `responseOpen` which keeps a history of all redirects performed in the interim, together with the first 1024 bytes of their response bodies.

Since 0.4.1

withResponseHistory :: Request -> Manager -> (HistoriedResponse BodyReader -> IO a) -> IO a Source #

A variant of `withResponse` which keeps a history of all redirects performed in the interim, together with the first 1024 bytes of their response bodies.

Since 0.4.1

managerSetInsecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings Source #

Set the proxy override value, only for HTTP (insecure) connections.

Since 0.4.7

managerSetSecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings Source #

Set the proxy override value, only for HTTPS (secure) connections.

Since 0.4.7

managerSetProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings Source #

Set the proxy override value, for both HTTP (insecure) and HTTPS (insecure) connections.

Since 0.4.7

managerSetMaxHeaderLength :: Int -> ManagerSettings -> ManagerSettings Source #

managerSetMaxNumberHeaders :: Int -> ManagerSettings -> ManagerSettings Source #

responseTimeoutMicro :: Int -> ResponseTimeout Source #

Specify maximum time in microseconds the retrieval of response headers is allowed to take

Since: http-client-0.5.0

responseTimeoutNone :: ResponseTimeout Source #

Do not have a response timeout

Since: http-client-0.5.0

responseTimeoutDefault :: ResponseTimeout Source #

Use the default response timeout

When used on a `Request`, means: use the manager's timeout value

When used on a `ManagerSettings`, means: default to 30 seconds

Since: http-client-0.5.0

httpLbs :: (MonadIO m, HasHttpManager env, MonadReader env m) => Request -> m (Response ByteString) Source #

Same as `httpLbs`, except it uses the `Manager` in the reader environment.

Since 2.1.1

httpNoBody :: (MonadIO m, HasHttpManager env, MonadReader env m) => Request -> m (Response ()) Source #

Same as `httpNoBody`, except it uses the `Manager` in the reader environment.

This can be more convenient that using `withManager` as it avoids the need to specify the base monad for the response body.

Since 2.1.2

# Lower-level conduit functions

requestBodySource :: Int64 -> ConduitM () ByteString IO () -> RequestBody Source #

requestBodySourceChunked :: ConduitM () ByteString IO () -> RequestBody Source #

bodyReaderSource :: forall (m :: Type -> Type) i. MonadIO m => BodyReader -> ConduitM i ByteString m () Source #