Class Web
Outbound HTTP and HTTPS for server-side binaries. Backed by libcurl, so TLS verification, redirects, chunked decoding and the system certificate store all come from a library that is maintained for the purpose.
Distinct from Http, which is a raw-socket plaintext client for the host
runtime's loopback control protocol. Use this one for anything real.
Certificate store. A dynamically linked build finds the system CA bundle.
A fully static build has whatever the image provides, which for a scratch
container is nothing - and TLS then fails with "unable to get local issuer
certificate". Ship a ca-certificates.crt and point curl at it with the
CURL_CA_BUNDLE or SSL_CERT_FILE environment variable (the first one set
wins). The native client reads them and hands the file to libcurl, which
would not read either on its own.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classOne streamed HTTP exchange: the request body written as it is produced, the response read as it arrives, neither held in memory whole.static final classAn outbound response: status, body, and libcurl's message when it failed. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe request has no body.static final longThe request has a body whose length is not known in advance: chunked on HTTP/1.1, DATA frames until the end on HTTP/2. -
Method Summary
Modifier and TypeMethodDescriptionstatic Web.Resultstatic Web.Resultstatic Web.ExchangeOpens a streamed exchange; seeWeb.Exchange.static Web.Resultstatic Web.Resultheaders: a list of "Name: value" strings, or null
-
Field Details
-
NO_BODY
public static final long NO_BODYThe request has no body.- See Also:
-
UNKNOWN_LENGTH
public static final long UNKNOWN_LENGTHThe request has a body whose length is not known in advance: chunked on HTTP/1.1, DATA frames until the end on HTTP/2.- See Also:
-
-
Method Details
-
get
- Throws:
IOException
-
getJson
- Throws:
IOException
-
postJson
- Throws:
IOException
-
request
public static Web.Result request(String method, String url, List headers, byte[] body) throws IOException headers: a list of "Name: value" strings, or null
Every default and no connection pool; a
WebClientis the way to set a client certificate, require HTTP/2, change a timeout or reuse connections.- Throws:
IOException
-
open
public static Web.Exchange open(String method, String url, List headers, long requestLength) throws IOException Opens a streamed exchange; seeWeb.Exchange. Every default, no pool.- Throws:
IOException
-