Module HTTP/Client

This module is undocumented. This is a list of its definitions.

NO_FAILURE_HANDLER :: Throwable -> <Proc> ()
NO_RESPONSE_HANDLER :: Response -> <Proc> ()
acceptEncoding :: Builder -> [String] -> <Proc> Builder

Sets the content encodings the request declares as acceptable, that is, its Accept-Encoding header.

acceptLanguage :: Builder -> [String] -> <Proc> Builder
acceptMediaType :: Builder -> [MediaType] -> <Proc> Builder

Sets the media types the request declares as acceptable, that is, its Accept header. Use [WILDCARD_TYPE] to accept anything.

asyncInvoke :: Invocation -> (Response -> <Proc> ()) -> (Throwable -> <Proc> ()) -> <Proc> Future Response

Sends the request without waiting for the response and returns a future for it. Exactly one of the two handlers is called when the exchange ends: the first with the response, whatever its status, or the second with the failure that prevented a response.

The handlers run in a background thread, in an SCL context derived from the one that was current when the request was submitted. Anything the response owns, including the client, must be released by the handlers rather than by the caller, which returns first.

build :: Builder -> String -> <Proc> Invocation

Builds an invocation for an arbitrary HTTP method, named by the string, and without a request entity.

buildClient :: ClientBuilder -> <Proc> Client

Creates a client from the given configuration. Support for multipart entities is registered into the client, so entities built with the HTTP/MultiPart module can be sent through it.

The result owns network resources and must be released with close.

buildDelete :: Builder -> <Proc> Invocation

Builds a DELETE invocation from the request built so far.

buildGet :: Builder -> <Proc> Invocation

Builds a GET invocation from the request built so far.

buildPost :: Builder -> Entity -> <Proc> Invocation

Builds a POST invocation that sends the given entity as the request body.

buildPut :: Builder -> Entity -> <Proc> Invocation

Builds a PUT invocation that sends the given entity as the request body.

chunkedPost :: Client -> String -> File -> Integer -> <Proc,Exception> Response

POSTs the contents of the file to the URL as application/octet-stream, using chunked transfer encoding with the given chunk size in bytes. The request also carries a Content-Disposition header naming the file.

The chunking settings are set on the client itself, so they stay in effect for the requests made through that client afterwards.

chunkedPostAuth :: Client -> String -> File -> Integer -> String -> <Proc,Exception> Response

As chunkedPost, with the last argument sent as the value of the Authorization header. The value is used as it stands, so it has to include the scheme, as in Bearer <token>.

chunkedPut :: Client -> String -> File -> Integer -> <Proc,Exception> Response

As chunkedPost, but sends the file with PUT instead of POST.

chunkedPutAuth :: Client -> String -> File -> Integer -> String -> <Proc,Exception> Response

As chunkedPut, with the last argument sent as the value of the Authorization header. The value is used as it stands, so it has to include the scheme, as in Bearer <token>.

clientBuilder :: <Proc> ClientBuilder

A client configuration with the default settings.

close :: Client -> <Proc> ()

Closes the client and releases the connections and threads it holds. A client that is not closed leaks them, so close it once the last response obtained through it has been read.

entity :: a -> MediaType -> <Proc> Entity

An entity that sends the given value as the given media type. The value is converted to bytes by the writer the client has for that combination of value type and media type; a String, a File and a MultiPart all work out of the box.

formEntity :: Form -> <Proc> Entity

An entity that sends the form as application/x-www-form-urlencoded.

onReadProgress :: WebTarget -> (Long -> <Proc> ()) -> <Proc> ()

Registers a callback that is called while a response entity is being read through the given target. The argument is the number of bytes read so far, counted from the beginning of the entity.

onWriteProgress :: WebTarget -> (Long -> <Proc> ()) -> <Proc> ()

Registers a callback that is called while a request entity is being written through the given target. The argument is the number of bytes written so far, counted from the beginning of the entity.

path :: WebTarget -> String -> <Proc> WebTarget

Returns a new target whose URI is the given path appended to the URI of the given target.

possibleContentLengthOf :: Response -> <Proc> Maybe Long

The length of the response entity as announced by its Content-Length header. Nothing if the response has no such header or its value is not a number, which is what a server sends when it streams a response of unknown length.

possibleHeaderOf :: Response -> String -> <Proc> Maybe String

The value of the named header, or Nothing if the response has no such header. Header names are compared case insensitively, and a header that occurs several times is returned as its values joined with commas.

property :: Client -> String -> a -> <Proc> Dynamic

Sets a configuration property of the client, and returns the client itself. The property affects every request made through the client afterwards.

readEntity :: VecComp a => Response -> <Proc,Exception> a

Reads the entity of the response and converts it to the expected type, which is determined by the context in which the result is used; String is the usual choice.

Reading consumes the underlying stream, so this can normally be done only once per response; a second attempt fails. It also fails if the server sent no entity, or if no reader is registered for the combination of the response media type and the expected type.

readEntity_ :: Response -> Class a -> <Proc,Exception> a
request :: WebTarget -> <Proc> Builder

Starts building a request against the target.

statusCodeOf :: Response -> <Proc> Integer

The HTTP status code of the response, for example 200 or 404.

statusMessageOf :: Response -> <Proc> String

The reason phrase that belongs to the status of the response, for example Not Found. It is empty for a status the implementation does not know.

syncInvoke :: Invocation -> <Proc,Exception> Response

Sends the request and waits for the response.

An unsuccessful HTTP status is not an error here: the response is returned whatever its status, and the status is read with statusCodeOf. Only a failure to complete the exchange at all, such as an I/O error or a failure of a request or response filter, raises an exception.

target :: Client -> String -> <Proc> WebTarget

A target for the given URI, against which requests can then be built.

trustAllClientBuilder :: <Proc> ClientBuilder

A client configuration that accepts every server certificate and every host name without checking either. This gives up the protection TLS provides against a man-in-the-middle, so use it only against servers you control, such as a test server with a self-signed certificate.