ddn.api.net.http.client
Module ddn.api.net.http.client
Defines a small, robust, and idiomatic HTTP client API that supports both synchronous and asynchronous usage.
Types 10
Base exception type for the HTTP client API.
this(string msg, string file = __FILE__, size_t line = __LINE__,
Throwable next = null)Constructs an HTTP exception.Exception thrown when an HTTP operation times out.
this(string msg, string file = __FILE__, size_t line = __LINE__,
Throwable next = null)Constructs a timeout exception.Standard HTTP methods.
A case-insensitive header map with multi-value support.
Header names are normalized to lower case for lookups. Each name can carry several values — required for response headers that legally repeat (e.g. Set-Cookie, which must not be comma-folded per RFC 6265). set replaces all values of a name; add appends one; get returns the first value and getAll returns every value.
private string[][string] _valuesvoid opIndexAssign(string value, string name)Map-like assignment: `headers["name"] = "value"`.void opIndexAssign(typeof(null), string name)Map-like delete: `headers["name"] = null`.int opApply(scope int delegate(const string name, const string value) dg) constForeach iteration over every stored (name, value) pair; a name with several values yields one iteration per value.void set(string name, string value)Sets (replaces) a header with a single value.void add(string name, string value)Appends a value to a header, preserving any existing values — use for legally repeatable headers such as `Set-Cookie`.void remove(string name)Removes a header (all its values) if present.const(string[][string]) values() @property constReturns the underlying normalized header map (name to all values).An HTTP request.
HttpMethod methodstring urlHttpHeaders headersubyte[] bodyDuration operationTimeoutDuration connectTimeoutuint maxRedirectsHttpRequest withHeader(string name, string value) constReturns a copy of this request with an additional/replaced header.HttpRequest withOperationTimeout(Duration d) constReturns a copy of this request with an operation timeout.HttpRequest withConnectTimeout(Duration d) constReturns a copy of this request with a connect timeout.this(HttpMethod method, string url)Constructs a request with the given method and URL.An HTTP response.
string header(string name, string defaultValue = "") constConvenience accessor for a header on the response.Synchronous HTTP client interface.
HttpResponse request(const HttpRequest request)Performs an HTTP request and returns the full response.void close()Releases any resources associated with the client.A future representing an asynchronously produced value.
private SharedState _statebool ready()Returns true if the future is already completed.void wait()Blocks until the future is completed.T get()Blocks until completion, then returns the value or throws the stored error.this(SharedState state)SharedStateA promise that can be completed with a value or an error.
private SharedState _stateHttpFuture!T future()Returns the future associated with this promise.void succeed(T value)Completes the promise successfully.void fail(Throwable error)Completes the promise with an error.Asynchronous HTTP client interface.
HttpFuture!HttpResponse requestAsync(const HttpRequest request)Starts an HTTP request and returns a future for its response.void close()Releases any resources associated with the client.Functions 1
string asciiLower(string s) @safe pure nothrowLower-cases a header name using ASCII only, returning the original string (no allocation) when it is already lower-case.