Restify Version - 4.0.2
Node.js Version - 6.11.3
Expected behaviour
Once i have the gzip enabled at the application startUp. I am not able to find the options to disable it based on the header parameters or any flag being passed.
const app = restify.createServer();
app.use(restify.gzipResponse());
Actual behaviour
Cannot find any option to disable to gzip once enabled so that i can have the flag option to zip few responses and not zip few based on my functionality needs.
Repro case
const app = restify.createServer();
app.use(restify.gzipResponse());
swaggerRestify.register(app);
const port = 20010;
app.listen(port);
Why do you want this?
It gives me the flexibility to not zip the response for few of the API calls and based on the environment variable can have the option and disable it.
This seems like a reasonable feature request. The plugin could probably take a function that returns a boolean?
It is nice to be able to enable compression at the application level but the ability to override is missing. The ability to disable compression on a call basis could prove to be very useful during debugging and development cycles.
In the short term you could wrap your own logic around it. Something like this could work:
server.use(function(req, res, next) {
var gzip = restify.gzipResponse();
if (someLogic) {
return gzip(req, res, next);
}
return next();
});
@DonutEspresso This logic is still applied globally. What if you have a request header like x-no-compression and for that call you want to not compress the response? This still uses a server level setting as opposed to a call/request level setting. Thoughts or suggestions?
I would also like to add that weighting does not see to work with the accept-encoding header. An 'accept-encoding' header of 'gzip;q=0.5, identity;q=1.0, *;q=0' returns gzipped content.
Overall this looks good :heart:! If you want to take a pass at an API proposal for this (we don't really have a template, just throw out some ideas about how you would want to see it work :smile:) I would be happy to review it and help you with getting a PR landed!
Wouldn't req.headers['accept-encoding'] = null disable compression?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed as stale because it has not had recent activity.