Plasma GitLab Archive
Projects Blog Knowledge

Module Http_client.Convenience


module Convenience: sig .. end


Convenience module for simple applications

Do open Http_client.Convenience for simple applications.

The functions of this module share the following behaviour:

The environment variables http_proxy and no_proxy determine the proxy settings. http_proxy must be an http-URL that contains the proxy's name, its port, and optionally user and password. E.g. "http://eric:ericspassword@proxy:8080/". The variable no_proxy is a comma-separated list of hosts and domains for which no proxy must be used. E.g. "localhost, sun, moon, .intra.net"

There is a default behaviour for authentication. Both "basic" and "digest" methods are enabled. Two global variables, http_user and http_password set the user and password if the URL does not specify them. In the case that user and password are included in the URL, these values are always used.

There is a default error behaviour. If a request fails, it is automatically repeated. The variable http_trials specifies the number of times a request is submitted at most. Requests are not repeated if there is a HTTP return code that indicates a normal operating condition. POST and DELETE requests are never repeated.

Error codes are reported as Http_client.Http_error. Note that this is different than what the pipeline core does.

Thread safety

The Convenience module is fully thread-safe with the exception of the exported variables (http_trials, http_user, and http_password). Note that all threads share the same pipeline, and access to the pipeline is serialized. The latter simply means that it always works, but that threads may block each other (i.e. the program slows down if more than one thread wants to open http connections at the same time).

val http_trials : int Pervasives.ref
number of times every request is tried. Default: 3
val http_user : string Pervasives.ref
The default user if authentication is required
val http_password : string Pervasives.ref
The default password if authentication is required
val http_get_message : string -> Http_client.http_call
Does a "GET" request with the given URL and returns the message
val http_head_message : string -> Http_client.http_call
Does a "HEAD" request with the given URL and returns the reply.
val http_post_message : string -> (string * string) list -> Http_client.http_call
Does a "POST" request with the given URL and returns the reply. The list contains the parameters sent with the POST request.
val http_put_message : string -> string -> Http_client.http_call
Does a "PUT" request with the given URL and returns the reply. The second argument contains the contents to be put.
val http_delete_message : string -> Http_client.http_call
Does a "DELETE" request with the given URL and returns the reply.
val http_get : string -> string
Does a "GET" request with the given URL and returns the message body
val http_post : string -> (string * string) list -> string
Does a "POST" request with the given URL and returns the response body. The list contains the parameters send with the POST request.
val http_put : string -> string -> string
Does a "PUT" request with the given URL and returns the response body. The second argument contains the contents to be put.
val http_delete : string -> string
Does a "DELETE" request with the given URL and returns the response body.
val http_verbose : unit -> unit
Turns on debug messages on stderr.
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml