github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/logfmt/lib/body_parser_stream.js (about) 1 var split = require('split'); 2 var through = require('through'); 3 var Readable = require('stream').Readable; 4 var PassThrough = require('stream').PassThrough; 5 var logfmt = require('../logfmt'); 6 7 exports = module.exports = function(options){ 8 if(options == null) options = {}; 9 var mime = options.contentType || "application/logplex-1"; 10 11 return function(req, res, next) { 12 13 //honor already parsed bodies 14 if (req._body) return next(); 15 16 //mime-type check 17 var is_mime = req.header('content-type') === mime; 18 if (!is_mime) return next(); 19 req._body = true; 20 req.body = new PassThrough({objectMode: true}); 21 req.pipe(logfmt.streamParser()).pipe(req.body); 22 23 return next(); 24 } 25 } 26