Adds zlib as parser to the body-parser library, so you can convert incoming gzipped data into a string representation.
This is really useful if you want to read gziped requests to save size
npm install --save express body-parser body-parser-zlib
This library adds a zlib
method to the body-parser
object.
Initialise like so:
var bodyParser = require('body-parser');
require('body-parser-zlib')(bodyParser);
Once initialised, you can use it just like any other body-parser
middleware:
var app = require('express')();
app.use(bodyParser.zlib());
This will parse any gzipped request and place it as a JavaScript object on req.body
for your route handlers to use.
var express = require('express'),
bodyParser = require('body-parser');
require('body-parser-zlib')(bodyParser);
var app = express();
app.use(bodyParser.zlib());
app.post('/users', function(req, res, body) {
// Any request with an Zlib payload will be parsed
// and a String produced on req.body
// corresponding to the request payload.
console.log(req.body);
res.status(200).end();
});
For Single routes
var express = require('express'),
bodyParser = require('body-parser');
var zlibParser;
var app = express();
require('body-parser-zlib')(bodyParser);
zlibParser = bodyParser.zlib();
app.post('/users', zlibParser, function(req, res, body) {
// Any request to this route with a
// Zlib payload will be parsed
// and a String produced on req.body
// corresponding to the request payload.
console.log(req.body);
res.status(200).end();
});
This library was born out of a frustration that body-parser doesn't support parsing gzipped content if the corresponding header was not set. The provided functionality gives you the ability to control when you want to decompress a request regardless of the headers set. This makes it especially useful when communicating with legacy systems.
GPL General Public License v3.0