HttpClient

Implements a HTTP client connection to a single server.

Constructors

this
this(Duration timeout, Connector connector)

Constructor.

Members

Functions

adaptConnection
IConnection adaptConnection(IConnection conn)
Undocumented in source. Be warned that the author may not have intended to support it.
connect
void connect(HttpRequest request)

Connect to a request's destination.

connected
bool connected()

Returns true if a connection is active (whether due to an in-flight request or due to keep-alive).

disconnect
void disconnect(string reason)

Close the connection to the HTTP server.

expectResponse
void expectResponse()

Called to set up the client to be ready to receive a response.

finalizeResponse
HttpResponse finalizeResponse()

Wrap up and return the current response, and clean up the client for another request.

getNextRequest
HttpRequest getNextRequest()

Pop off a request from the queue and return it, while incrementing sentRequests.

isIdle
bool isIdle()

Returns true when we are connected but not waiting for anything. Requests can always be sent immediately when this is true.

normalizeRequest
void normalizeRequest(HttpRequest request)

Fix up a response to set up required headers, etc. Done automatically by request, unless called with normalize == false.

onConnect
void onConnect()

Called when the underlying connection (TCP, TLS...) is established.

onContinuation
void onContinuation(Data data)

Received data handler used while we are receiving the response body.

onData
void onData(Data[] data)

Called when we've received some data from the response body.

onDisconnect
void onDisconnect(string reason, DisconnectType type)

Disconnect handler

onDone
void onDone(Data[] rest, string disconnectReason, bool error)

Called when we've read the entirety of the response. Any left-over data is in rest. disconnectReason is null if there was no disconnect.

onHeaderData
void onHeaderData(Data[] data)

Called when we've received some data from the response headers.

onHeadersReceived
void onHeadersReceived()

Called when we've read all headers (currentResponse.headers is populated).

onIdle
void onIdle()

Called when we're ready to send a request.

onNewResponse
void onNewResponse(Data data)

Received data handler used while we are receiving headers.

request
void request(HttpRequest request, bool normalize)

Send a HTTP request.

sendRequest
void sendRequest(HttpRequest request)

Encode and send a request (headers and body) to the connection. Has no other side effects.

submitResponse
void submitResponse(HttpResponse response, string reason)

Submit a received response.

Variables

agent
string agent;

User-Agent header to advertise.

conn
IConnection conn;
Undocumented in source.
connector
Connector connector;
Undocumented in source.
currentResponse
HttpResponse currentResponse;
Undocumented in source.
expect
size_t expect;
Undocumented in source.
handleDisconnect
void delegate(string disconnectReason, DisconnectType type) handleDisconnect;

Optional disconnect callback. Generally using this only makes sense with a persistent connection with keepAlive=true.

handleResponse
void delegate(HttpResponse response, string disconnectReason) handleResponse;

User-supplied callback for handling the response.

headerBuffer
DataVec headerBuffer;
Undocumented in source.
keepAlive
bool keepAlive;

Keep connection alive after one request.

pipelining
bool pipelining;

Send requests without waiting for a response. Requires keepAlive.

receivedResponses
ulong receivedResponses;
Undocumented in source.
requestQueue
HttpRequest[] requestQueue;
Undocumented in source.
sentRequests
ulong sentRequests;
Undocumented in source.
timer
TimeoutAdapter timer;
Undocumented in source.

Meta