Skip to content
turn (req,res) pairs into a single duplex stream
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example
test
.travis.yml
LICENSE
index.js
package.json
readme.markdown

readme.markdown

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

Something went wrong with that request. Please try again.