compression icon indicating copy to clipboard operation
compression copied to clipboard

Force compression to client don't work

Open zhaoyou opened this issue 8 years ago • 3 comments

I want compression response body to client always , Whether the client have any Settings。My Client App is poor what can't set any request header, but can handle compression data.

app.get('/device', auth_identity, compression({filter: function(req, res) { return true;}}),device);
node: v4.2.2
compression: 1.6.1
express : 3.4.4

Why ? thanks.

zhaoyou avatar May 18 '16 05:05 zhaoyou

@dougwilson

zhaoyou avatar May 20 '16 03:05 zhaoyou

Hi @zhaoyou, sorry I haven't gotten back to you yet. Yes, this is a hole in the module currently, that you cannot override the way the module checks if the client is capable of receiving compressed content, and I think it would be good to add it.

In the meantime, I would like the offer the following work-around for your use-case:

app.get('/device', auth_identity, always_compress, compression(), device)

function always_compress (req, res, next) {
  req.headers['accept-encoding'] = 'gzip'
  next()
}

dougwilson avatar May 20 '16 03:05 dougwilson

@dougwilson Thanks 👍 for your explanation and suggestion.

zhaoyou avatar May 20 '16 05:05 zhaoyou