Created
January 23, 2014 07:42
-
-
Save threez/8574532 to your computer and use it in GitHub Desktop.
In this example I played with the internal node http parser. This might be useful to folks that have to parse HTTP manually. For more info look at: https://github.com/joyent/node/blob/master/lib/_http_client.js
This file contains 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
var HTTPParser = process.binding('http_parser').HTTPParser; | |
var parser = require("http").parsers.alloc(); | |
parser.reinitialize(HTTPParser.RESPONSE); | |
parser.onBody = function(body) { | |
console.log(body.toString()); | |
} | |
parser.onIncoming = function(response) { | |
console.log(response.headers); | |
console.log(response.statusCode); | |
}; | |
function parse(data) { | |
var buffer = new Buffer(data); | |
parser.execute(buffer, 0, buffer.length); | |
} | |
parse("HTTP/1.1 200 OK\r\n"); | |
parse("Date: Fri, 13 Jan 2006 15:12:48 GMT\r\n"); | |
parse("Last-Modified: Tue, 1"); | |
parse("0 Jan 2006 11:18:20 GMT\r\n"); | |
parse("Content-"); | |
parse("Language: de\r\n"); | |
parse("Content-Type: text/html; charset=utf-8\r\n"); | |
parse("Content-Length: 24\r\n"); | |
parse("\r\n"); | |
parse("search=Katzen&go=Artikel"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment