request ~config ~authenticator ~meth ~headers ~body ~max_redirect ~follow_redirect ~happy_eyeballs uri f init
does a single request of uri
and returns the response. Each time part of the body is received, f acc part
is called, with acc
being the last return value of f
(or init
if it is the first time) and part
being the body part received. If follow_redirect
is true (the default), and there's a redirection, f
is not called with the (potential) body of the redirection page.
By default, up to 5 redirects (max_redirect
) are followed. If follow_redirect
is false, no redirect is followed (defaults to true). The default HTTP request type (meth
) is GET
.
If no tls_config
is provided, a default one is used, with alpn and authenticators. If a tls_config
is provided, this is used unmodified.
If no config
is provided (the default), and the uri
uses the https
schema, application layer next protocol negotiation (ALPN) is used to negotiate HTTP2 (prefered) or HTTP1. If the uri
uses the http
schema, HTTP1 is used by default (unless the config
provided is `H2
).
The default authenticator
is from the ca-certs
opam package, which discovers and uses the system trust anchors.
The happy-eyeballs
opam package is used to establish the TCP connection, which prefers IPv6 over IPv4.