This module contains everything you need to initiate HTTP connections. If
you want a simple interface based on URLs, you can use simpleHttp. If you
want raw power, http is the underlying workhorse of this package. Some
examples:

The following headers are automatically set by this module, and should not
be added to requestHeaders:

Content-Length

Host

Accept-Encoding (not currently set, but client usage of this variable will cause breakage).

Any network code on Windows requires some initialization, and the network
library provides withSocketsDo to perform it. Therefore, proper usage of
this library will always involve calling that function at some point. The
best approach is to simply call them at the beginning of your main function,
such as:

Perform a request

Download the specified URL, following any redirects, and
return the response body.

This function will throwIO an HttpException for any
response with a non-2xx status code (besides 3xx redirects up
to a limit of 10 redirects). It uses parseUrl to parse the
input. This function essentially wraps httpLbsRedirect.

Note: Even though this function returns a lazy bytestring, it
does not utilize lazy I/O, and therefore the entire response
body will live in memory. If you want constant memory usage,
you'll need to use the conduit package and http or
httpRedirect directly.

This is a simplified version of http for the common case where you simply
want the response data as a simple datatype. If you want more power, such as
interleaved actions on the response body during download, you'll need to use
http directly. This function is defined as:

Even though the Response contains a lazy bytestring, this
function does not utilize lazy I/O, and therefore the entire
response body will live in memory. If you want constant memory
usage, you'll need to use conduit packages's
Source returned by http.

Note: Unlike previous versions, this function will perform redirects, as
specified by the redirectCount setting.

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
Source. The Response contains the status code
and headers that were sent back to us, and the
Source contains the body of the request. Note
that this Source allows you to have fully
interleaved IO actions during your HTTP download, making it
possible to download very large responses in constant memory.
You may also directly connect the returned Source
into a Sink, perhaps a file or another socket.

Note: Unlike previous versions, this function will perform redirects, as
specified by the redirectCount setting.

Request

The constructor for this data type is not exposed. Instead, you should use
either the def method to retrieve a default instance, or parseUrl to
construct from a URL, and then use the records below to make modifications.
This approach allows http-conduit to add configuration options without
breaking backwards compatibility.

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

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: