Skip to content

point-of-media/body-parser-zlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gzip Body Parser

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

Build Status npm version Dependency Status devDependency Status

Installation

npm install --save express body-parser body-parser-zlib

Usage

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.

Example

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();
});

Motivation

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.

License

GPL General Public License v3.0

About

a Plugin to the express body parser to parse zlibed content

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published