12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849module juptune.http.client;
struct HttpClient
{
/++ ALIASES ++/
/// A function provided by HttpClient which can be used to push data into the request body.
alias PutBodyFunc = Result function(const const ubyte[] bodyChunk);
/// ditto
alias PutBodyFuncGC = Result function(const const ubyte[] bodyChunk);
/// A function provided by the user which is used to stream an entire request body.
alias StreamRequestFunc = Result function(Result function(const const ubyte[] bodyChunk) putter);
/// ditto
alias StreamRequestFuncGC = Result function(Result function(const const ubyte[] bodyChunk) putter);
/// A function provided by HttpClient which can be used to stream read data from the response body.
alias StreamResponseFunc = Result function(HttpResponse statusAndHeaders, const const ubyte[] bodyChunk);
/// ditto
alias StreamResponseFuncGC = Result function(HttpResponse statusAndHeaders, const const ubyte[] bodyChunk);
///
alias __xdtor = __MARMOS_BUG__;
///
alias __xpostblit = __MARMOS_BUG__;
/++ FUNCTIONS ++/
/// Closes the connection to the server.
Result close();
/// Connects this client to the given IP address.
Result connect(IpAddress ip, const const char[] host = null);
/// Connects this client to the given IP address over TLS.
Result connectTls(IpAddress ip, const const char[] host);
///
TlsTcpSocket getTlsSocketForUnittests();
/// Returns whether this client is connected to a server.
bool isConnected();
///
HttpClient opAssign(HttpClient p);
/// Sends a request to the server and returns the response.
Result request(HttpRequest request, HttpResponse response);
/// Returns the version of HTTP that this client is using.
HttpClientVersion selectedVersion();
/// Streams a request to the server and streams the response.
Result streamRequest(HttpRequest request, HttpResponse response, Result function(Result function(const const ubyte[] bodyChunk) putter) bodyPutter, Result function(HttpResponse statusAndHeaders, const const ubyte[] bodyChunk) bodyReader);
/// ditto
Result streamRequestGC(HttpRequest request, HttpResponse response, Result function(Result function(const const ubyte[] bodyChunk) putter) bodyPutter, Result function(HttpResponse statusAndHeaders, const const ubyte[] bodyChunk) bodyReader);
///
static void wrapPairedSocket(HttpClient client, TcpSocket socket, HttpClientConfig config);
}
A medium-level HTTP client, designed to be a good balance between ease of use, flexibility, and performance.
This client attempts to cater to both the @nogc and GC worlds, and as such has a few different named overloads for its functions.
It has two different ways to send a request currently: A 'Simple' way, and a 'Streamed' way.
This is the easiest way to send a request, but isn't the most suitable for all situations, especially sending/receiving large amounts of data.
This method is used by calling the requestfunction with a pre-built HttpRequestcontaining the entire request. Please consult the documentation for HttpRequestand requestfor more info.
This is the most flexible way to send a request beyond using the low-level primitives directly, but is more complex to use. This is the recommended way to send/receive large amounts of data.
This method is used by calling the streamRequestfunction which provides a callback-based pattern for sending/receiving data. Please consult the documentation for streamRequestfor more info.
| Name | Description |
|---|---|
| PutBodyFunc |
A function provided by |
| PutBodyFuncGC |
ditto |
| StreamRequestFunc |
A function provided by the user which is used to stream an entire request body. |
| StreamRequestFuncGC |
ditto |
| StreamResponseFunc |
A function provided by |
| StreamResponseFuncGC |
ditto |
| __xdtor | |
| __xpostblit |
| Name | Description |
|---|---|
| close |
Closes the connection to the server. |
| connect |
Connects this client to the given IP address. |
| connectTls |
Connects this client to the given IP address over TLS. |
| getTlsSocketForUnittests | |
| isConnected |
Returns whether this client is connected to a server. |
| opAssign | |
| request |
Sends a request to the server and returns the response. |
| selectedVersion |
Returns the version of HTTP that this client is using. |
| streamRequest |
Streams a request to the server and streams the response. |
| streamRequestGC |
ditto |
| wrapPairedSocket |