Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: e5c3561cc3
Fetching contributors…

Cannot retrieve contributors at this time

63 lines (43 sloc) 1.248 kB

http-duplex

Turn (req,res) pairs into a single readable/writable stream.

build status

example

var httpDuplex = require('http-duplex');
var http = require('http');
var fs = require('fs');

var server = http.createServer(function (req, res) {
    var dup = httpDuplex(req, res);
    console.log(dup.method + ' ' + dup.url);

    dup.setHeader('content-type', 'text/plain');

    if (dup.method === 'POST') {
        dup.pipe(process.stdout, { end : false });
        dup.on('end', function () {
            dup.end('ok\n');
        });
    }
    else fs.createReadStream(__filename).pipe(dup)
});

server.listen(8484);
$ curl -s http://localhost:8484 | tail -n1
server.listen(8484);
$ curl -sd 'beep boop' http://localhost:8484
ok

methods

var httpDuplex = require('http-duplex')

var dup = httpDuplex(req, res)

Return a new readable/writable duplex stream dup from the http request req and http response res.

dup has all the same methods has both req and res, but on a single object.

install

With npm do:

npm install http-duplex

license

MIT

Jump to Line
Something went wrong with that request. Please try again.