node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



HTTP parser written in node with hooks into the raw header and raw body.

You should only need this module if you're writing an HTTP proxy or something similarly nefarious.

build status



var parsley = require('parsley');
var net = require('net');
net.createServer(function (stream) {
    parsley(stream, function (req) {
        req.on('headers', function (headers) {
            console.log(req.method + ' ' + req.url + 'HTTP/' + req.httpVersion);
$ curl localhost:7000/zing
$ node example/headers.js 
GET /zingHTTP/1.1
{ 'user-agent': 'curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/ libidn/1.18',
  host: 'localhost:7000',
  accept: '*/*' }


var parsley = require('parsley');
var net = require('net');
net.createServer(function (stream) {
    parsley(stream, function (req) {
        var head = [];
        req.on('rawHead', function (buf) {
        var body = [];
        req.on('rawBody', function (buf) {
        req.on('end', function () {
$ echo beep | curl -sNT. localhost:7000
$ node example/raw.js 
[ 'PUT ',
  '/ ',
  ' curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/ libidn/1.18\r\n',
  ' localhost:7000\r\n',
  ' */*\r\n',
  ' chunked\r\n',
  ' 100-continue\r\n',
  '\r\n' ]
[ '5\r\n', 'beep\n', '\r\n', '0\r\n', '\r\n' ]


var parsley = require('parsley')

var p = parsley(stream, cb)

Parse stream, calling cb with a new http.IncomingMessage object as soon as the first piece of data comes in.

If the connection is keep-alive, multiple requests may come through cb on the same stream.


Put the parser into upgrade mode manually. This is done automatically when the "upgrade" header is present or "connection: upgrade".


The http.IncomingMessage that cb gets called with has these events:

"data", buf

Emitted when data comes in not including the extra pieces like transfer-encoding framing.

"headers", headers

Emitted when all the req.headers have arrived.


Emitted when all the request data has been received, not including trailing framing such as the last newline.

"rawHead", buf

Emitted whenever any data comes in before the body.

"rawBody", buf

Emitted whenever any data comes in after the header but before the request ends for the case of keep-alive requests.


Emitter when the request is complete, including any trailing framing.

"error", err

Emitted when the stream fails to parse.


Turns out, it's super hard to get node's http parser to spit out the raw request buffers only for a particular request. But with parsley, you can listen on 'rawHead' and 'rawBody' events to get the raw buffer stream as it gets parsed.


With npm do:

npm install parsley