# Module Nethttp_client.Convenience

    module Convenience: sig .. end

Convenience module for simple applications

Do `open Nethttp_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. Note that basic authentication is by default only enabled over connections that are secured via TLS! You can change that with the function `configure`, see below.

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 `Nethttp_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 Stdlib.ref

number of times every request is tried. Default: 3

    val http_user : string Stdlib.ref

The default user if authentication is required

    val http_password : string Stdlib.ref

The default password if authentication is required

    val configure : ?insecure:bool -> unit -> unit

Configurations:

- `insecure`: whether basic authentication over non-TLS connections is enabled

You can only configure before the first user.

    val configure_pipeline : (Nethttp_client.pipeline -> unit) -> unit

This function will be called before the pipeline is used. This is intended for fine-grained configuration.

    val http_get_message : string -> Nethttp_client.http_call

Does a "GET" request with the given URL and returns the message

    val http_head_message : string -> Nethttp_client.http_call

Does a "HEAD" request with the given URL and returns the reply.

    val http_post_message : string -> (string * string) list -> Nethttp_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 -> Nethttp_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 -> Nethttp_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 : ?verbose_status:bool ->
           ?verbose_request_header:bool ->
           ?verbose_response_header:bool ->
           ?verbose_request_contents:bool ->
           ?verbose_response_contents:bool ->
           ?verbose_connection:bool -> ?verbose_events:bool -> unit -> unit

Turns on debug messages on stderr. By default, all options are turned on.