arsd.http2

This is version 2 of my http/1.1 client implementation.

More...

Members

Classes

FormData
class FormData

Creates a multipart/form-data object that is suitable for file uploads and other kinds of POST

HttpApiClient
class HttpApiClient()

An experimental component for working with REST apis. Note that it is a zero-argument template, so to create one, use new HttpApiClient!()(args..) or you will get "HttpApiClient is used as a type" compile errors.

HttpClient
class HttpClient

HttpClient keeps cookies, location, and some other state to reuse connections, when possible, like a web browser. You can use it as your entry point to make http requests.

HttpMockProvider
class HttpMockProvider

A pseudo-cache to provide a mock server. Construct one of these, populate it with test responses, and pass it to HttpClient to do a network-free test.

HttpRequest
class HttpRequest

Represents a HTTP request. You usually create these through a HttpClient.

WebSocket
class WebSocket

WebSocket client, based on the browser api, though also with other api options.

Enums

CertificateFileFormat
enum CertificateFileFormat

Supported file formats for HttpClient.setClientCert. These are loaded by OpenSSL in the current implementation.

HttpVerb
enum HttpVerb

Functions

get
HttpRequest get(string url)

auto request = get("http://arsdnet.net/"); request.send();

getText
string getText(string url)

gets the text off a url. basic operation only.

post
HttpRequest post(string url, string[string] req)

Do not forget to call waitForCompletion() on the returned object!

waitForFirstToComplete
HttpRequest waitForFirstToComplete(Duration timeout, HttpRequest[] requests)
HttpRequest waitForFirstToComplete(HttpRequest[] requests)

Waits for the first of the given requests to be either aborted or completed. Returns the first one in that state, or null if the operation was interrupted or reached the given timeout before any completed. (If it returns null even before the timeout, it might be because the user pressed ctrl+c, so you should consider checking if you should cancel the operation. If not, you can simply call it again with the same arguments to start waiting again.)

Interfaces

ICache
interface ICache
Undocumented in source.

Structs

BasicAuth
struct BasicAuth
CookieHeader
struct CookieHeader
HttpCookie
struct HttpCookie
HttpRequestParameters
struct HttpRequestParameters
Undocumented in source.
HttpRequestsAsTheyComplete
struct HttpRequestsAsTheyComplete

An input range that runs waitForFirstToComplete but only returning each request once. Before you loop over it, you can set some properties to customize behavior.

HttpResponse
struct HttpResponse
LinkHeader
struct LinkHeader
Uri
struct Uri

Represents a URI. It offers named access to the components and relative uri resolution, though as a user of the library, you'd mostly just construct it like Uri("http://example.com/index.html").

Templates

addToSimpledisplayEventLoop
template addToSimpledisplayEventLoop()

Warning: you should call this AFTER websocket.connect or else it might throw on connect because the function sets nonblocking mode and the connect function doesn't handle that well (it throws on the "would block" condition in that function. easier to just do that first)

Detailed Description

It has no dependencies for basic operation, but does require OpenSSL libraries (or compatible) to be support HTTPS. This dynamically loaded on-demand (meaning it won't be loaded if you don't use it, but if you do use it, the openssl dynamic libraries must be found in the system search path).

You can compile with -version=without_openssl to entirely disable ssl support.

http2.d, despite its name, does NOT implement HTTP/2.0, but this shouldn't matter for 99.9% of usage, since all servers will continue to support HTTP/1.1 for a very long time.

Examples

import arsd.http2;

void main() {
	auto client = new HttpClient();

	auto request = client.request(Uri("http://dlang.org/"));
	auto response = request.waitForCompletion();

	import std.stdio;
	writeln(response.contentText);
	writeln(response.code, " ", response.codeText);
	writeln(response.contentType);
}

Meta

History

Automatic 100 Continue handling was added on September 28, 2021. It doesn't set the Expect header, so it isn't supposed to happen, but plenty of web servers don't follow the standard anyway.