msgraph.httpd.daemon

Simple HTTP daemon
License: BSL-1.0.
struct Httpd;
HTTP daemon
Examples:
import std.socket;
import std.parallelism;
import std.string;
import std.range;
import std.algorithm;
Httpd httpd;
httpd.listen();
ushort port = httpd.listeningPort;
auto t = task({
	// curlでGET確認
	import std.net.curl: get, HTTP;
	auto client = HTTP();
	client.setUserAgent("hoge");
	auto res = get(format!"http://localhost:%d"(port), client);
	assert(res == "SUCCESS");
	assert(client.responseHeaders["content-type"] == "text/plain");
	assert(client.statusLine.code == 200);
	assert(client.statusLine.reason == "OK");
});
t.executeInNewThread();
Request req;
auto reqresult = httpd.receive(req, 1000.msecs);
assert(reqresult);
assert(req.header["host"] == format!"localhost:%d"(port));
assert(req.header["user-agent"] == "hoge");
httpd.send(Response(HttpStatusLine.ok, "SUCCESS", "text/plain"));
t.yieldForce();
@safe this(string bindaddr, ushort port = 0);
@trusted void listen(string bindaddr = "localhost", ushort port = 0);
const @trusted ushort listeningPort();
@trusted void closeListener();
@trusted void closeClient();
@safe bool receive(out Request req, Duration timeout = Duration.max);
@safe bool send(Response res, Duration timeout = 1000.msecs);
@safe void close();
package(msgraph) auto asyncComm(ref Httpd httpd, Response delegate(ref Request req) onRecv, Duration recvTimeout = 30.seconds, Duration sendTimeout = 1000.msecs);