New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

http-raw

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-raw

expose the raw request data in an http server

latest
Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
22
22.22%
Maintainers
1
Weekly downloads
 
Created
Source

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 rs = req.createRawBodyStream();
        var ws = res.createRawStream();
        
        ws.write('HTTP/1.1 200 OK\r\n\r\n');
        rs.pipe(upper()).pipe(ws)
    }
});
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 httpRaw = require('http-raw')

The http-raw api is exactly like the http.createServer(cb) api from core, except for the extra functions documented below that get attached to the req and res objects in the 'request' and 'upgrade' events.

var server = httpRaw(cb)

Create a new http server with extended raw stream functions.

var server = httpRaw.https(options, cb)

Create a new https server with extended raw stream functions.

var rs = req.createRawStream()

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

On the same tick as the response handler, s.buffers will contain an array of all the buffered data.

On the next tick s.buffers gets set to undefined to it can be garbage collected.

To get all the data, req.createRawStream() must be fired on the same tick as the response callback.

var ws = res.createRawStream()

Return a writable stream ws that will be written directly to the underlying network socket without any additional framing added.

var bs = req.createRawBodyStream()

Return a readable stream bs like the stream returned by req.createRawStream(), but only emit the raw body data, not the headers.

To get all the data, req.createRawBodyStream() must be fired on the same tick as the response callback.

install

With npm do:

npm install http-raw

license

MIT

Keywords

http

FAQs

Package last updated on 19 Mar 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts