http-raw
expose the raw request data in an http server
Last updated 13 years ago by substack .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install http-raw 
SYNC missed versions from official npm registry.

http-raw

expose the raw request data in an http server

build status

example

var createServer = require('http-raw');
var through = require('through');

var server = createServer(function (req, res) {
    if (req.method === 'GET') {
        res.end('beep boop\n');
    }
    else {
        var bs = req.createRawBodyStream();
        bs.write('HTTP/1.1 200 OK\r\n\r\n');
        bs.pipe(upper()).pipe(bs)
    }
});
server.listen(7000);

function upper () {
    return through(function (buf) {
        this.emit('data', String(buf).toUpperCase());
    });
}
$ node example/server.js &
$ nc localhost 7000
PUT / HTTP/1.1
Host: robots

HTTP/1.1 200 OK


beep 
BEEP
boop
BOOP

methods

var createServer = require('http-raw')

The http-raw api is exactly like the http.createServer(cb) api from core, except that 2 extra functions are available on the req objects from the cb(req,res) handler:

req.createRawStream()

Return a readable/writable stream s. s will emit all the raw data from the connection, including the buffered header data without doing any parsing on the data beforehand.

Writing to s goes through to the underlying network socket without any additional framing applied.

var s = req.createRawBodyStream()

Return a readable/writable stream s. s will emit the raw data from after the headers have been parsed, including any framing without doing any parsing.

Writing to s goes through to the underlying network socket without any additional framing applied.

install

With npm do:

npm install http-raw

license

MIT

Current Tags

  • 2.1.0                                ...           latest (13 years ago)

11 Versions

  • 2.1.0                                ...           13 years ago
  • 2.0.1                                ...           13 years ago
  • 2.0.0                                ...           13 years ago
  • 1.1.0                                ...           13 years ago
  • 1.0.0                                ...           13 years ago
  • 0.2.0                                ...           13 years ago
  • 0.1.0                                ...           13 years ago
  • 0.0.3                                ...           13 years ago
  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago
  • 0.0.0                                ...           13 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |