A port of Maxwell Flynn's HTTP request/response builder/parser atomizes.
Simply add atomized to your project's dub dependencies. For example:
"dependencies": {
"atomized": "~>1.0.0"
}
All that's necessary to include the library is this:
import atomized;
HTTPMessage response = new HTTPMessage;
response.setStatusCode(200)
.setHeader("Content-Type", "text/plain")
.setHeader("Connection", "close")
.setMessageBody("Hello world!");
writeln(response);
This results in the following output:
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Content-Length: 12
Hello world!
HTTPMessage request = new HTTPMessage;
request.setMethod(MessageMethod.GET)
.setPath("/")
.setHeader("Host", "example.com")
.setHeader("User-Agent", "Test Agent")
.setHeader("Connection", "keep-alive");
writeln(request);
This results in the following output:
GET / HTTP/1.1
User-Agent: Test Agent
Host: example.com
Connection: keep-alive
string requestString = "GET / HTTP/1.1\r\nHost: example.com\r\nUser-Agent: Test Agent\r\nConnection: keep-alive\r\n\r\n";
HTTPMessage request = new HTTPMessage;
HTTPMessageParser parser = new HTTPMessageParser;
parser.parse(request, requestString);
writeln(request);
This results in the following output:
GET / HTTP/1.1
User-Agent: Test Agent
Host: example.com
Connection: keep-alive
atomize(s/d) is licensed under the MIT license.