NodeJS GZip compression

Not applicable

Hi,

Any suggestions on how to rnable the GZIP compression on the nodejs api proxy application? i tried using the compression.algorithm property of the proxy endpoint configuration, but gzip compression is not done..

I had tried using the compression module inside nodejs, and it results in some _implicitHeader errors? Had anybody achieved the GZIP compresiion for the JSON responses returned from the nodejs proxy?

Thanks,

Prem

1 7 4,368
7 REPLIES 7

typically you do not have to do anything in node or apigee, if the client requests compression, the response will be compressed,

For eg,

Client will send a 'Accept-Encoding' header with 'gzip' or 'deflate' as values to it, the response from apigee will be automatically compressed with requested encoding scheme.

Not applicable

Hi,

It is not happening.. i had added a simple hello world nodejs application, which returns a JSON object, and when i request the url in chrome, i cant see the response in gzip, though request headers has gzip in the accept-encoding. Please find the nodejs code i had used below.

Example Nodejs application:

var express = require('express'); var app = express(); console.log('node.js application starting...'); app.get('/', function(req, res) { var returnValue = {'foo':'bar'} res.send(returnValue); }); app.listen(3000);

With Express 3.x, the default threshold for compression is 1024. So if your content length is not greater than 1024, compression does not occur. To always use compression, you can use "app.use(express.compress({threshold: 0})); and that *should* work. So while it appears the compression middleware isn't working, it is...it's just choosing not to compress due to the content being smaller than the compression threshold.

Also, if you want to run this on Edge, we are currently investigating an issue with using the "compression" module (Express 4.x+) and "express.compress()" (Express 3.x) that results in a StackOverflow. So while the information above is accurate for enabling compression with Express 3.x, there is a known issue with this on Edge.

I have an Express 4.x Node endpoint that is not getting gZipped. I've tried using the middleware (which does not work), but according to Apigee documentation, the compression should automatically be set according to what the client requests.

http://api.meredith.com/rest/application/v1/advertisement/gpt?callback=adSetup&adSlot=div-gpt-mob-sq...

So which is it? Does Apigee take care of the compression automatically, or do you need to use middleware? Neither approach is working for me at present.

Not applicable

Can we get a response to this? We are trying to impliment gzipping but getting garbage returned. http://dev.api.meredith.com/rest/application/v1/advertisement/gpt?callback=adSetup&adSlot=div-gpt-sq...

vineetb
Participant I

Is there any update on this issue? I am also getting the error -

Script execution failed: Cannot find function _implicitHeader in object [object Object].: at end
(/organization/environment/api/node_modules/compression/index.js:102)\n at
/organization/environment/api/controllers/controller.js:290\n at
/organization/environment/api/node_modules/xml2js/lib/xml2js.js:489\n at emit (events.js:95)\n at
/organization/environment/api/node_modules/xml2js/lib/xml2js.js:447\n at emit
(/organization/environment/api/node_modules/xml2js/node_modules/sax/lib/sax.js:640)\n at emitNode
(/organization/environment/api/node_modules/xml2js/node_modules/sax/lib/sax.js:645)\n at closeTag
(/organization/environment/api/node_modules/xml2js/node_modules/sax/lib/sax.js:905)\n at write
(/organization/environment/api/node_modules/xml2js/node_modules/sax/lib/sax.js:1449)\n at
/organization/environment/api/node_modules/xml2js/lib/xml2js.js:508\n at
/organization/environment/api/node_modules/xml2js/lib/xml2js.js:7\n at
/organization/environment/api/node_modules/xml2js/lib/xml2js.js:540\n at callback
(/organization/environment/api/controllers/controller.js:273)\n at /node_modules/request/request.js:122\n at
emit (events.js:98)\n at /node_modules/request/request.js:888\n at emit (events.js:117)\n at
/node_modules/request/request.js:839\n at emit (events.js:117)\n at _stream_readable.js:943\n at
_tickDomainCallback (trireme.js:491)\n at _tickFromSpinner (trireme.js:422)\n",