123456789101112131415module juptune.http.client;
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
);
Streams a request to the server and streams the response.
This is the 'Streamed' way to send a request, and is the most flexible to use.
The responseparameter will only contain the status line, headers, and trailers (on return), and will not contain the body unless the user's callback puts it there.
The requestparameter is used to provide the method, path, and headers, but the body is always ignored.
The D compiler is really bad with error messages, so you may need to store bodyPutterand bodyReaderin a variable before passing them to this function just to get a useful error message.
e.g. scope HttpClient.StreamRequestFunc putter = (...) @trusted @nogc {...}
This function will automatically add the Hostheader if it is not already present.
If the request has a body and does not have a Content-Lengthor Transfer-Encodingheader, then this function will automatically add a Transfer-Encoding: chunkedheader.
If the request does not have a Hostheader, then this function will automatically add one using the hostprovided by the relevant connect function that was used.
The client will gracefully close the connection in normal circumstances such as the Connection: closeheader being present.
The state of the responseparameter is undefined if this function returns an error.
This function will automatically close the connection if an error occurs.
The client must be connected.
Anything that TcpSocket.sendor TcpSocket.receivecan throw.
If using HTTP1, anything that Http1Writeror Http1Readercan throw (`Http1Error`).
Anything the user returns from bodyPutteror bodyReader.
A Resultindicating whether the request was successful or not.