Conduit powered version of withResponse. Differences are:
Response body is represented as a
Producer.Generalized to any instance of
MonadUnliftIO, not justIO.The
Manageris contained by aMonadReadercontext.
Since 2.1.0
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Modulehttp-conduit-2.3.9.1Haskell2010
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.
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
Conduit-powered version of responseOpen.
See withResponse for the differences with responseOpen.
Since 2.1.0
Generalized version of responseClose.
Since 2.1.0
An Acquire for getting a Response.
Since 2.1.0
Same as httpSource, but uses Manager from Reader environment instead of the global one.
Since 2.3.6
TLS-powered manager settings.
Since 2.1.0
Get a new manager using defaultManagerSettings.
Since 2.1.0
Get a new manager using the given settings.
Since 2.1.0
Define a HTTP proxy, consisting of a hostname and port number.
ProxyproxyHost :: ByteStringThe host name of the HTTP proxy in URI format. IPv6 addresses in square brackets.
proxyPort :: IntThe port number of the HTTP proxy.
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
RequestBodyLBS ByteStringRequestBodyBS ByteStringRequestBodyBuilder Int64 BuilderRequestBodyStream 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).
IsString RequestBodyDefined in http-client-0.7.19 · Network.HTTP.Client.TypesSince 0.4.12
Semigroup RequestBodyDefined in http-client-0.7.19 · Network.HTTP.Client.TypesMonoid RequestBodyDefined in http-client-0.7.19 · Network.HTTP.Client.TypesAll 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
Show RequestDefined in http-client-0.7.19 · Network.HTTP.Client.TypesIsString RequestDefined in http-client-0.7.19 · Network.HTTP.Client.Request · orphanParses a URL via parseRequest_
NOTE: Prior to version 0.5.0, this instance used parseUrlThrow instead.
HTTP request method, eg GET, POST.
Since 0.1.0
Whether to use HTTPS (ie, SSL).
Since 0.1.0
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
The port to connect to. Also used for generating the host request header.
Since 0.1.0
Everything from the host to the query string.
Since 0.1.0
Query string appended to the path.
Since 0.1.0
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
Request body to be sent to the server.
Since 0.1.0
Optional HTTP proxy.
Since 0.1.0
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
How many redirects to follow when getting a resource. 0 means follow no redirects. Default value: 10.
Since 0.1.0
Decide whether a header must be stripped from the request when following a redirect. Default: keep all headers intact.
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).
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
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
HTTP version to send to server.
Default: HTTP 1.1
Since 0.4.3
Called every time an HTTP 103 Early Hints header section is received from the server.
List of header values being redacted in case we show Request.
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)
Set the query string to the given key/value pairs.
Since 0.3.6
A simple representation of the HTTP response.
Since 0.1.0
Functor ResponseDefined in http-client-0.7.19 · Network.HTTP.Client.TypesFoldable ResponseDefined in http-client-0.7.19 · Network.HTTP.Client.TypesTraversable ResponseDefined in http-client-0.7.19 · Network.HTTP.Client.TypesShow body => Show (Response body)Defined in http-client-0.7.19 · Network.HTTP.Client.TypesStatus code of the response.
Since 0.1.0
HTTP version used by the server.
Since 0.1.0
Response headers sent by the server.
Since 0.1.0
Response body sent by the server.
Since 0.1.0
Cookies set on the client after interacting with the server. If
cookies have been disabled by setting cookieJar to Nothing, then
this will always be empty.
Since 0.1.0
Early response headers sent by the server, as part of an HTTP 103 Early Hints section.
Since 0.7.16
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
HasHttpManager ManagerDefined in http-client-0.7.19 · Network.HTTP.Client.TypesSettings 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
Number of connections to a single host to keep alive. Default: 10.
Since 0.1.0
Default timeout to be applied to requests which do not provide a timeout value.
Default is 30 seconds
Create a TLS connection. Default behavior: throw an exception that TLS is not supported.
Since 0.1.0
Total number of idle connection to keep open at a given time.
This limit helps deal with the case where you are making a large number of connections to different hosts. Without this limit, you could run out of file descriptors. Additionally, it can be set to zero to prevent reuse of any connections. Doing this is useful when the server your application is talking to sits behind a load balancer.
Default: 512
Since 0.3.7
Perform the given modification to a Request before performing it.
This function may be called more than once during request processing. see https://github.com/snoyberg/http-client/issues/350
Default: no modification
Since 0.4.4
Perform the given modification to a Response after receiving it.
Default: no modification
Create an insecure connection.
Since 0.1.0
Exceptions for which we should retry our request if we were reusing an already open connection. In the case of IOExceptions, for example, we assume that the connection was closed on the server and therefore open a new one.
Since 0.1.0
Action wrapped around all attempted Requests, usually used to wrap
up exceptions in library-specific types.
Default: wrap all IOExceptions in the InternalException constructor.
How to deal with timing out on retrieval of response headers.
Eq ResponseTimeoutDefined in http-client-0.7.19 · Network.HTTP.Client.TypesShow ResponseTimeoutDefined in http-client-0.7.19 · Network.HTTP.Client.TypesStatusCodeException (Response ()) ByteStringGenerated by the parseUrlThrow function when the
server returns a non-2XX response status code.
May include the beginning of the response body.
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.
OverlongHeadersToo many total bytes in the HTTP header were returned by the server.
TooManyHeaderFieldsToo many HTTP header fields were returned by the server.
ResponseTimeoutThe server took too long to return a response. This can be altered via responseTimeout or managerResponseTimeout.
ConnectionTimeoutAttempting to connect to the server timed out.
ConnectionFailure SomeExceptionAn exception occurred when trying to connect to the server.
InvalidStatusLine ByteStringThe status line returned by the server could not be parsed.
InvalidHeader ByteStringThe given response header line could not be parsed
InvalidRequestHeader ByteStringThe given request header is not compliant (e.g. has newlines)
InternalException SomeExceptionAn 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.
ProxyConnectException ByteString Int StatusA non-200 status code was returned when trying to connect to the proxy server on the given host and port.
NoResponseDataReceivedNo 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.
TlsNotSupportedException 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.
WrongRequestBodyStreamSize Word64 Word64The request body provided did not match the expected size.
Provides the expected and actual size.
ResponseBodyTooShort Word64 Word64The returned response body is too short. Provides the expected size and actual size.
InvalidChunkHeadersA chunked response body had invalid headers.
IncompleteHeadersAn incomplete set of response headers were returned.
InvalidDestinationHost ByteStringThe host we tried to connect to is invalid (e.g., an empty string).
HttpZlibException ZlibExceptionAn exception was thrown when inflating a response body.
InvalidProxyEnvironmentVariable Text TextValues in the proxy environment variable were invalid. Provides the environment variable name and its value.
ConnectionClosedAttempted to use a Connection which was already closed
InvalidProxySettings TextProxy settings are not valid (Windows specific currently) @since 0.5.7
Show HttpExceptionContentDefined in http-client-0.7.19 · Network.HTTP.Client.TypesSpecify maximum time in microseconds the retrieval of response headers is allowed to take
Do not have a response timeout
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
Read CookieJarDefined in http-client-0.7.19 · Network.HTTP.Client.TypesShow CookieJarDefined in http-client-0.7.19 · Network.HTTP.Client.TypesSemigroup CookieJarDefined in http-client-0.7.19 · Network.HTTP.Client.TypesMonoid CookieJarDefined in http-client-0.7.19 · Network.HTTP.Client.TypesSince 1.9
Deprecated. Please use parseUrlThrow, parseRequest, or parseRequest_ instead
Deprecated synonym for parseUrlThrow. You probably want parseRequest or parseRequest_ instead.
Same as parseRequest, except will throw an HttpException in the event of a non-2XX response. This uses throwErrorStatusCodes to implement checkResponse.
Convert a URL into a Request.
This function defaults some of the values in Request, such as setting method to
and requestHeaders to GET[].
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
Same as parseRequest, but parse errors cause an impure exception. Mostly useful for static strings which are known to be correctly formatted.
A default request value, a GET request of localhost/:80, with an empty request body.
Note that the default checkResponse does nothing.
Add a Basic Auth header (with the specified user name and password) to the given Request. Ignore error handling:
applyBasicAuth "user" "pass" $ parseRequest_ urlNOTE: 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
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
An exception which may be generated by this library
HttpExceptionRequest Request HttpExceptionContentMost exceptions are specific to a Request. Inspect the HttpExceptionContent value for details on what occurred.
InvalidUrlException String StringA URL (first field) is invalid for a given reason (second argument).
Show HttpExceptionDefined in http-client-0.7.19 · Network.HTTP.Client.TypesException HttpExceptionDefined in http-client-0.7.19 · Network.HTTP.Client.TypesModify the request so that non-2XX status codes do not generate a runtime StatusCodeException.
Modify the request so that non-2XX status codes generate a runtime StatusCodeException, by using throwErrorStatusCodes
getHttpManager :: a -> ManagerHasHttpManager ManagerDefined in http-client-0.7.19 · Network.HTTP.Client.TypesA 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
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
Create a new Connection from a read, write, and close function.
Create a new Connection from a Socket.
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
computeCookieString :: RequestInput request
-> CookieJarCurrent cookie jar
-> UTCTimeValue that should be used as "now"
-> BoolWhether 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"
This corresponds to the subcomponent algorithm entitled "Paths" detailed in section 5.1.4
This corresponds to the subcomponent algorithm entitled "Domain Matching" detailed in section 5.1.3
evictExpiredCookies This corresponds to the eviction algorithm described in Section 5.3 "Storage Model"
generateCookie :: SetCookieThe SetCookie we are encountering
-> RequestThe request that originated the response that yielded the SetCookie
-> UTCTimeValue that should be used as "now"
-> BoolWhether or not this request is coming from an "http" source (not javascript or anything like that)
-> Maybe CookieThe optional output cookie
Turn a SetCookie into a Cookie, if it is valid
insertCheckedCookie Insert a cookie created by generateCookie into the cookie jar (or not if it shouldn't be allowed in)
This applies the computeCookieString to a given Request
isPotentiallyTrustworthyOrigin :: BoolTrue if HTTPS
-> ByteStringHost
-> BoolWhether 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
This corresponds to the subcomponent algorithm entitled "Path-Match" detailed in section 5.1.4
receiveSetCookie :: SetCookieThe SetCookie the cookie jar is receiving
-> RequestThe request that originated the response that yielded the SetCookie
-> UTCTimeValue that should be used as "now"
-> BoolWhether or not this request is coming from an "http" source (not javascript or anything like that)
-> CookieJarInput cookie jar to modify
-> CookieJarUpdated 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.
updateCookieJar This applies receiveSetCookie to a given Response
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 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
Never connect using a proxy, regardless of the proxy value in the Request.
Since 0.4.7
proxyEnvironmentNamed :: Textenvironment variable name
-> Maybe Proxyfallback if no environment set
-> ProxyOverrideSame as proxyEnvironment, but instead of default environment variable names, allows you to set your own name.
Since 0.4.7
Get the proxy settings from the Request itself.
Since 0.4.7
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
Same as rawConnectionModifySocket, but also takes in a chunk size.
Use the given proxy settings, regardless of the proxy value in the Request.
Since 0.4.7
Send secure requests to the proxy in plain text rather than using CONNECT,
regardless of the value in the Request.
Deprecated. Use newManager instead
Create, use and close a Manager.
Since 0.2.1
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
Add a Bearer Auth header to the given Request
Extract a URI from the request.
Since 0.1.0
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
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
and requestHeaders to GET[].
A Request created by this function won't cause exceptions on non-2XX response status codes.
Same as requestFromURI, but if the conversion would fail, throws an impure exception.
Set the query string to the given key/value pairs.
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
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.
Retrieve the orignal Request from a Response
Note that the requestBody is not available and always set to empty.
A function which must be provided with a Popper.
Since 0.1.0
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
How the HTTP proxy server settings should be discovered.
Since 0.4.7
Status of streaming a request body from a file.
Since 0.4.9
Eq StreamFileStatusDefined in http-client-0.7.19 · Network.HTTP.Client.TypesOrd StreamFileStatusDefined in http-client-0.7.19 · Network.HTTP.Client.TypesShow StreamFileStatusDefined in http-client-0.7.19 · Network.HTTP.Client.TypesInstead of instance Ord Cookie. See equalCookie, equivCookie.
See equalCookie.
Equality of name, domain, path only. This corresponds to step 11 of the algorithm
described in Section 5.3 "Storage Model". See also: equal.
See equalCookieJar, equalCookie.
A datatype holding information on redirected requests and the final response.
Since 0.4.1
Functor HistoriedResponseDefined in http-client-0.7.19 · Network.HTTP.ClientFoldable HistoriedResponseDefined in http-client-0.7.19 · Network.HTTP.ClientTraversable HistoriedResponseDefined in http-client-0.7.19 · Network.HTTP.ClientShow body => Show (HistoriedResponse body)Defined in http-client-0.7.19 · Network.HTTP.ClientGeneric (HistoriedResponse body)Defined in http-client-0.7.19 · Network.HTTP.Clienttype Rep (HistoriedResponse body) = D1 ('MetaData "HistoriedResponse"
"Network.HTTP.Client"
"http-client-0.7.19-HrfOahD9xgrKGFtDZYGgUO"
'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)))))Defined in http-client-0.7.19 · Network.HTTP.ClientRequests which resulted in a redirect, together with their responses. The response contains the first 1024 bytes of the body.
Since 0.4.1
The final request performed.
Since 0.4.1
The response from the final request.
Since 0.4.1
Set the proxy override value, only for HTTP (insecure) connections.
Since 0.4.7
Set the proxy override value, for both HTTP (insecure) and HTTPS (insecure) connections.
Since 0.4.7
Set the proxy override value, only for HTTPS (secure) connections.
Since 0.4.7
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
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
Same as httpLbs, except it uses the Manager in the reader environment.
Since 2.1.1
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