HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulehttp-client-0.7.19Haskell2010

Network.HTTP.Client.Internal

Note that this is essentially the "kitchen sink" export module, including many functions intended only to be used internally by this package. No API stability is guaranteed for this module. If you see functions here which you believe should be promoted to a stable API, please contact the author.

  • 29 types
  • 1 class
  • 108 values

Low-level response body handling

9 declarations

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

Note that in order to consume the entire request body, you will need to repeatedly call this function until you receive an empty ByteString as a result.

Since 0.1.0

Raw connection handling

11 declarations

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

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

@since

Cookies

15 declarations
valuereceiveSetCookie
  1. :: SetCookie

    The SetCookie the cookie jar is receiving

  2. -> Request

    The request that originated the response that yielded the SetCookie

  3. -> UTCTime

    Value that should be used as "now"

  4. -> Bool

    Whether or not this request is coming from an "http" source (not javascript or anything like that)

  5. -> CookieJar

    Input cookie jar to modify

  6. -> 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.

valuegenerateCookie
  1. :: SetCookie

    The SetCookie we are encountering

  2. -> Request

    The request that originated the response that yielded the SetCookie

  3. -> UTCTime

    Value that should be used as "now"

  4. -> Bool

    Whether or not this request is coming from an "http" source (not javascript or anything like that)

  5. -> Maybe Cookie

    The optional output cookie

#

Turn a SetCookie into a Cookie, if it is valid

valueinsertCheckedCookie
  1. :: Cookie

    The SetCookie the cookie jar is receiving

  2. -> CookieJar

    Input cookie jar to modify

  3. -> Bool

    Whether or not this request is coming from an "http" source (not javascript or anything like that)

  4. -> 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)

valuecomputeCookieString
  1. :: Request

    Input request

  2. -> CookieJar

    Current cookie jar

  3. -> UTCTime

    Value that should be used as "now"

  4. -> Bool

    Whether or not this request is coming from an "http" source (not javascript or anything like that)

  5. -> (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"

valuedomainMatches
  1. :: ByteString

    Domain to test

  2. -> ByteString

    Domain from a cookie

  3. -> Bool
#

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

Performing requests

13 declarations
valuewithResponse :: Request -> Manager -> (Response BodyReader -> IO a) -> IO a
#

Perform a Request using a connection acquired from the given Manager, and then provide the Response to the given function. This function is fully exception safe, guaranteeing that the response will be closed when the inner function exits. It is defined as:

withResponse req man f = bracket (responseOpen req man) responseClose f

It is recommended that you use this function in place of explicit calls to responseOpen and responseClose.

You will need to use functions such as brRead to consume the response body.

Since 0.1.0

A convenience wrapper around withResponse which reads in the entire response body and immediately closes the connection. Note that this function performs fully strict I/O, and only uses a lazy ByteString in its response for memory efficiency. If you are anticipating a large response body, you are encouraged to use withResponse and brRead instead.

Since 0.1.0

The most low-level function for initiating an HTTP request.

The first argument to this function gives a full specification on the request: the host to connect to, whether to use SSL, headers, etc. Please see Request for full details. The second argument specifies which Manager should be used.

This function then returns a Response with a BodyReader. The Response contains the status code and headers that were sent back to us, and the BodyReader contains the body of the request. Note that this BodyReader allows you to have fully interleaved IO actions during your HTTP download, making it possible to download very large responses in constant memory.

An important note: the response body returned by this function represents a live HTTP connection. As such, if you do not use the response body, an open socket will be retained indefinitely. You must be certain to call responseClose on this response to free up resources.

This function automatically performs any necessary redirects, as specified by the redirectCount setting.

When implementing a (reverse) proxy using this function or relating functions, it's wise to remove Transfer-Encoding:, Content-Length:, Content-Encoding: and Accept-Encoding: from request and response headers to be relayed.

Since 0.1.0

valueresponseClose :: Response a -> IO ()
#

Close any open resources associated with the given Response. In general, this will either close an active Connection or return it to the Manager to be reused.

Since 0.1.0

valuewithConnection :: Request -> Manager -> (Connection -> IO a) -> IO a
#

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).

The used Manager can be overridden (by requestManagerOverride) and the used Request can be modified (through managerModifyRequest). This function allows to retrieve the possibly overridden Manager and the possibly modified Request.

(In case the Manager is overridden by requestManagerOverride, the Request is being modified by managerModifyRequest of the new Manager, not the old one.)

Parse response headers

3 declarations

Request helper functions

29 declarations
valueparseRequest :: 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

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

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

Low-level response body handling

4 declarations

If a request is a redirection (status code 3xx) this function will create a new request from the old request, the server headers returned with the redirection, and the redirection code itself. This function returns Nothing if the code is not a 3xx, there is no location header included, or if the redirected response couldn't be parsed with parseRequest.

If a user of this library wants to know the url chain that results from a specific request, that user has to re-implement the redirect-following logic themselves. An example of that might look like this:

myHttp req man = do
   (res, redirectRequests) <- (`runStateT` []) $
        'httpRedirect'
            9000
            (\req' -> do
               res <- http req'{redirectCount=0} man
               modify (\rqs -> req' : rqs)
               return (res, getRedirectedRequest req req' (responseHeaders res) (responseCookieJar res) (W.statusCode (responseStatus res))
               )
            'lift'
            req
   applyCheckStatus (checkStatus req) res
   return redirectRequests

Manager

16 declarations

Create a Manager. The Manager will be shut down automatically via garbage collection.

Creating a new Manager is a relatively expensive operation, you are advised to share a single Manager between requests instead.

The first argument to this function is often defaultManagerSettings, though add-on libraries may provide a recommended replacement.

Since 0.1.0

valuecloseManager :: Manager -> IO ()
#

Deprecated. Manager will be closed for you automatically when no longer in use

Close all connections in a Manager.

Note that this doesn't affect currently in-flight connections, meaning you can safely use it without hurting any queries you may have concurrently running.

Since 0.1.0

datadata ManagerSettings
#

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

Constructors

Default value for ManagerSettings.

Note that this value does not have support for SSL/TLS. If you need to make any https connections, please use the http-client-tls package, which provides a tlsManagerSettings value.

Since 0.1.0

valuenoProxy :: ProxyOverride
#

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

Since 0.4.7

valueproxyEnvironment
  1. :: Maybe Proxy

    fallback if no environment set

  2. -> 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

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

All types

36 declarations
datadata Manager
#

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

Instances1HasHttpManager
datadata ManagerSettings
#

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

Constructors

datadata ResponseTimeout
#

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

Constructors

Instances2Eq, Show
datadata HttpExceptionContent
#

Constructors

Instances1Show
datadata Request
#

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

Constructors

  • Request
    • method :: Method

      HTTP request method, eg GET, POST.

      Since 0.1.0

    • secure :: Bool

      Whether to use HTTPS (ie, SSL).

      Since 0.1.0

    • host :: ByteString

      Requested host name, used for both the IP address to connect to and the host request header.

      This is in URI format, with raw IPv6 addresses enclosed in square brackets. Use strippedHostName when making network connections.

      Since 0.1.0

    • port :: Int

      The port to connect to. Also used for generating the host request header.

      Since 0.1.0

    • path :: ByteString

      Everything from the host to the query string.

      Since 0.1.0

    • queryString :: ByteString

      Query string appended to the path.

      Since 0.1.0

    • requestHeaders :: RequestHeaders

      Custom HTTP request headers

      The Content-Length and Transfer-Encoding headers are set automatically by this module, and shall not be added to requestHeaders.

      If not provided by the user, Host will automatically be set based on the host and port fields.

      Moreover, the Accept-Encoding header is set implicitly to gzip for convenience by default. This behaviour can be overridden if needed, by setting the header explicitly to a different value. In order to omit the Accept-Header altogether, set it to the empty string "". If you need an empty Accept-Header (i.e. requesting the identity encoding), set it to a non-empty white-space string, e.g. " ". See RFC 2616 section 14.3 for details about the semantics of the Accept-Header field. If you request a content-encoding not supported by this module, you will have to decode it yourself (see also the decompress field).

      Note: Multiple header fields with the same field-name will result in multiple header fields being sent and therefore it's the responsibility of the client code to ensure that the rules from RFC 2616 section 4.2 are honoured.

      Since 0.1.0

    • requestBody :: RequestBody

      Request body to be sent to the server.

      Since 0.1.0

    • proxy :: Maybe Proxy

      Optional HTTP proxy.

      Since 0.1.0

    • hostAddress :: Maybe HostAddress

      Optional resolved host address. May not be used by all backends.

      Since 0.1.0

    • rawBody :: Bool

      If True, a chunked and/or gzipped body will not be decoded. Use with caution.

      Since 0.1.0

    • decompress :: ByteString -> Bool

      Predicate to specify whether gzipped data should be decompressed on the fly (see alwaysDecompress and browserDecompress). Argument is the mime type. Default: browserDecompress.

      Since 0.1.0

    • redirectCount :: Int

      How many redirects to follow when getting a resource. 0 means follow no redirects. Default value: 10.

      Since 0.1.0

    • checkResponse :: Request -> Response BodyReader -> IO ()

      Check the response immediately after receiving the status and headers. This can be useful for throwing exceptions on non-success status codes.

      In previous versions of http-client, this went under the name checkStatus, but was renamed to avoid confusion about the new default behavior (doing nothing).

    • responseTimeout :: ResponseTimeout

      Number of microseconds to wait for a response (see ResponseTimeout for more information). Default: use managerResponseTimeout (which by default is 30 seconds).

      Since 0.1.0

    • cookieJar :: Maybe CookieJar

      A user-defined cookie jar. If Nothing, no cookie handling will take place, "Cookie" headers in requestHeaders will be sent raw, and responseCookieJar will be empty.

      Since 0.1.0

    • requestVersion :: HttpVersion

      HTTP version to send to server.

      Default: HTTP 1.1

      Since 0.4.3

    • onRequestBodyException :: SomeException -> IO ()

      How to deal with exceptions thrown while sending the request.

      Default: ignore IOExceptions, rethrow all other exceptions.

      Since: 0.4.6

    • requestManagerOverride :: Maybe Manager

      A Manager value that should override whatever Manager value was passed in to the HTTP request function manually. This is useful when dealing with implicit global managers, such as in Network.HTTP.Simple

    • shouldStripHeaderOnRedirect :: HeaderName -> Bool

      Decide whether a header must be stripped from the request when following a redirect. Default: keep all headers intact.

    • shouldStripHeaderOnRedirectIfOnDifferentHostOnly :: Bool

      Decide whether a header must be stripped from the request when following a redirect, if host differs from previous request in redirect chain. Default: false (always strip regardless of host change)

    • proxySecureMode :: ProxySecureMode

      How to proxy an HTTPS request.

      Default: Use HTTP CONNECT.

    • redactHeaders :: Set HeaderName

      List of header values being redacted in case we show Request.

    • earlyHintHeadersReceived :: [Header] -> IO ()

      Called every time an HTTP 103 Early Hints header section is received from the server.

Instances2Show, IsString
datadata RequestBody
#

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

Instances3IsString, Semigroup, Monoid
typetype Popper = IO ByteString
#

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

typetype GivesPopper a = NeedsPopper a -> IO a
#

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

datadata Response body
#

A simple representation of the HTTP response.

Since 0.1.0

Constructors

Instances4Functor, Foldable, Traversable, Show
typetype BodyReader = IO ByteString
#

An IO action that represents an incoming response body coming from the server. Data provided by this action has already been gunzipped and de-chunked, and respects any content-length headers present.

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

Since 0.4.0

datadata HttpException
#

An exception which may be generated by this library

Constructors

Instances2Show, Exception
valueequalCookie :: Cookie -> Cookie -> Bool
#

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.

valueequivCookie :: Cookie -> Cookie -> Bool
#

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

datadata Proxy
#

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

Constructors

Instances4Eq, Ord, Read, Show
  • Eq ProxyDefined in http-client-0.7.19 · Network.HTTP.Client.Types
  • Ord ProxyDefined in http-client-0.7.19 · Network.HTTP.Client.Types
  • Read ProxyDefined in http-client-0.7.19 · Network.HTTP.Client.Types
  • Show ProxyDefined in http-client-0.7.19 · Network.HTTP.Client.Types
datadata ProxySecureMode
#

Define how to make secure connections using a proxy server.

Constructors

  • ProxySecureWithConnect

    Use the HTTP CONNECT verb to forward a secure connection through the proxy.

  • ProxySecureWithoutConnect

    Send the request directly to the proxy with an https URL. This mode can be used to offload TLS handling to a trusted local proxy.

Instances4Eq, Ord, Read, Show
newtypenewtype MaxHeaderLength
#

The maximum header size in bytes.

Instances6Bounded, Enum, Eq, Num, Ord, Show
newtypenewtype MaxNumberHeaders
#

The maximum number of header fields.

Instances6Bounded, Enum, Eq, Num, Ord, Show

Various utilities

2 declarations
valuedummyManaged :: resource -> Managed resource
#

For testing purposes only: create a dummy Managed wrapper