Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test
.gitignore
package.json initial
pipes.js
readme.markdown

readme.markdown

mw-pipes

connect-compatible middleware connector, but with more elegant support for streams.

allow better support for streams that modify the request or response. next accepts optional _req, and _res arguments after the error parameter.

(these should be streams that are piped to or from the real req, res objects.)

var pipes = require('mw-pipes')
  , http = require('http')

http.createServer(
  pipes(
    function (req, res, next) {
      var x = new XStream()
      var y = new YStream()

      req.pipe(x)
      y.pipe(y)

      next(null, x, y)
    },
    ...

the properties of req and res will be copied onto x and y with getters/setters so that they will behave just like a regular ServerRequest and ServerResponse to downstream middleware.

Example

the following would fail using connect

var http = require('http')
  , pipes = require('mw-pipes')
  , BufferedStream = require('morestreams').BufferedStream
  ;

http.createServer(pipes(
  function (req, res, next) {
    var b = new BufferedStream()
    req.pipe(b)
    // replace the req stream with a buffered stream.
    // data events will be buffered until the pipe method is called.
    next(null, b)
  },
  function (req, res, next) {
    // this wouldn't work with connect.
    // the data events would get lost,
    setTimeout(function () {
      res.writeHeader(202)
      req.pipe(res)
    }, 1000)
  }
)).listen(8080)
Something went wrong with that request. Please try again.