vibe.d beta banner
get vibe.d
0.10.0

Asynchronous I/O that doesn’t get in your way, written in D

Function HTTPClient.request

Performs a HTTP request.

void request (
  scope void delegate(scope HTTPClientRequest) requester,
  scope void delegate(scope HTTPClientResponse) responder
) @trusted;

HTTPClientResponse request (
  scope void delegate(HTTPClientRequest) requester
) @safe;

requester is called first to populate the request with headers and the desired HTTP method and version. After a response has been received it is then passed to the caller which can in turn read the reponse body. Any part of the body that has not been processed will automatically be consumed and dropped.

Note that the requester callback might be invoked multiple times in the event that a request has to be resent due to a connection failure.

Also note that the second form of this method (returning a HTTPClientResponse) is not recommended to use as it may accidentially block a HTTP connection when only part of the response body was read and also requires a heap allocation for the response object. The callback based version on the other hand uses a stack allocation and guarantees that the request has been fully processed once it has returned.

Authors

Sönke Ludwig, Jan Krüger

Copyright

© 2012-2014 Sönke Ludwig

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.