Created
December 25, 2013 16:01
-
-
Save bithavoc/8124505 to your computer and use it in GitHub Desktop.
Example of joyent/http-parser bindings for D programming language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // http-parser.d example | |
| // http://blog.heapsource.com/post/70495154255/announcing-http-parser-d | |
| // | |
| import std.stdio; | |
| import http.parser.core; | |
| void main() { | |
| "http-parser.d in action with fixed-size Http Message Body".writeln; | |
| auto parser = new HttpParser(); | |
| parser.onMessageBegin = (parser) { | |
| writeln("Message has just begun"); | |
| }; | |
| parser.onMessageComplete = (parser) { | |
| writeln("Message has been completed"); | |
| }; | |
| parser.onUrl = (parser, string data) { | |
| writeln("Url of HTTP message is: ", data); | |
| }; | |
| parser.onStatusComplete = (parser) { | |
| writeln("HTTP status is complete"); | |
| }; | |
| parser.onHeader = (parser, HttpHeader header) { | |
| writeln("Parser Header '", header.name, "' with value '", header.value, "'"); | |
| }; | |
| parser.onBody = (parser, ubyte[] data) { | |
| writeln("A chunk of the HTTP bady has been processed: ", data); | |
| }; | |
| parser.execute("GET / HTTP 1.1\r"); | |
| parser.execute("\n"); | |
| parser.execute("FirstHeader: ValueOfFirst Header\r\n"); | |
| parser.execute("Content-Length: 3\r\n"); | |
| parser.execute("\r\n"); | |
| ubyte[] bodyChunk = [1u,2u,3u]; | |
| parser.execute(bodyChunk); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment