I created a small application rest node.js. I try to compress data json, which return by request api, but nothing compressed. Use express and compression.
var express = require('express');
var methodOverride = require('method-override');
var bodyParser = require('body-parser');
var serveStatic = require('serve-static');
var compression = require('compression');
var app = express();
app.use(compression());
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(bodyParser.json());
app.use(serveStatic('public', {'index': ['index.html']}));
app.use('/', require('./routes'));
app.use(function(req, res) {
res.sendfile('public/index.html');
});
app.disable('x-powered-by');
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
});
this response header without compession =(((
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 3756
ETag: W/"56IqvwOVCBB3MRndvDsFTA=="
Vary: Accept-Encoding
Date: Wed, 10 Jun 2015 14:21:11 GMT
Connection: keep-alive
Help.
Are you using plain curl to request it? Tell curl to ask for compressed data:
$ curl -H 'Accept-Encoding: gzip,deflate' -v -o tmp http://localhost:3000/
* Connected to localhost (::1) port 3000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: localhost:3000
> Accept: */*
> Accept-Encoding: gzip,deflate
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< ETag: W/"qIOLMe2deSCB3/8ol7nulg=="
< Vary: Accept-Encoding
< Content-Encoding: gzip # <========================================== !!!
< Date: Wed, 10 Jun 2015 16:14:50 GMT
< Connection: keep-alive
< Transfer-Encoding: chunked
Now the download is gzipped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With