Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

pass http server response methods through to the next destination pipe

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 test
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 LICENSE
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
Octocat-spinner-32 readme.markdown
readme.markdown

response-stream

Pass http server response methods through to the next destination pipe.

This is useful if you want to write duplex streams that will be piped into an http server response (.pipe(res)).

build status

example

var http = require('http');
var es = require('event-stream');
var filed = require('filed');
var responseStream = require('response-stream');

var server = http.createServer(function (req, res) {
    filed(__dirname + '/data.txt')
        .pipe(capStream())
        .pipe(res)
    ;
});
server.listen(8000);

function capStream () {
    return responseStream(es.mapSync(function (s) {
        return String(s).toUpperCase()
    }));
}

now our stream works plus we get all the nifty http headers from filed:

$ curl -i localhost:8000
HTTP/1.1 200 OK
content-type: text/plain
etag: f11d6d78081ea6d84ce2592001e9b510
last-modified: Tue, 28 Aug 2012 19:01:19 -0700
content-length: 10
Connection: keep-alive

BEEP BOOP

methods

var responseStream = require('response-stream')

var rs = responseStream(stream)

Return a new duplex stream from stream with all of the http server response methods that will be passed through to the destination response object.

events

rs.on('response', res)

Emitted after when the response object is available. All of the proxied methods will be passed through before this event fires

rs.on(method, args, prevent)

For each method: 'writeContinue', 'writeHead', 'setHeader', 'sendDate', 'getHeader', 'removeHeader', 'addTrailers'

corresponding to the http server response method, emit an event before the method is called on the actual response or saved with the arguments and a prevent() function that prevents passing the method call back to the response object.

install

With npm do:

npm install response-stream

license

MIT

Something went wrong with that request. Please try again.