1.0.1 • Published 8 years ago

express-transform v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

WIP

express-transform

Build Status

Install

npm install --save express-transform

Usage

Adds a req.transform method that can be used to pipe the response to transform streams before it is passed to the underlying socket.

See ./test/index.js.

Example for compressing response:

import express from 'express';
import onHeaders from 'on-headers';
import transform from 'express-transform';

const app = express();
app.use(transform());
app.use((req, res, next) => {
  const gzip = zlib.createGzip();
  res.transform(gzip);

  // Some express methods automatically
  // add Content-Length header which will
  // be incorrect since we are compressing.
  onHeaders(res, function gzipOnHeaders() {
    this.setHeader('Content-Encoding', 'gzip');
    this.removeHeader('Content-Length');
  });

  next();
});

app.use((req, res) => {
  res.send('Hello World!');
});