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

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!

Interfaces

ICache
interface ICache
Undocumented in source.

Structs

BasicAuth
struct BasicAuth
CookieHeader
struct CookieHeader
HttpCookie
struct HttpCookie
HttpRequestParameters
struct HttpRequestParameters
HttpResponse
struct HttpResponse
LinkHeader
struct LinkHeader
Uri
struct Uri

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.