I have a simple node application that should write metrics from clients. Clients send json-formatted metrics archived by the python zlib module, I'm trying to add middleware to unzip the request message before express tele-servicing happens.
My resellers are simply the default ones:
app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(express.cookieParser('your secret here')); app.use(express.session()); app.use(app.router); app.use(require('less-middleware')({ src: __dirname + '/public' })); app.use(express.static(path.join(__dirname, 'public'))); });
I tried adding simple middleware that receives data and then unpacks it:
app.use(function(req, res, next) { var data = ''; req.addListener("data", function(chunk) { data += chunk; }); req.addListener("end", function() { zlib.inflate(data, function(err, buffer) { if (!err) { req.body = buffer; next(); } else { next(err); } }); }); });
Problem with zlib.inflate I get this error:
Error: incorrect header check
Data is compressed using the python zlib module:
zlib.compress(jsonString)
but it seems that do not unpack, do not inflate, do not start gunzip.
source share