Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gzip support #56

Closed
WickyNilliams opened this issue Dec 8, 2013 · 29 comments · Fixed by #293
Closed

gzip support #56

WickyNilliams opened this issue Dec 8, 2013 · 29 comments · Fixed by #293
Milestone

Comments

@WickyNilliams
Copy link

Would it be possible to have an option for gzip/deflate compression?

@gr0uch
Copy link

gr0uch commented Feb 12, 2015

+1

@chadxz
Copy link

chadxz commented Mar 27, 2015

+1 would like this too

@hungsu
Copy link

hungsu commented Apr 21, 2015

+1 This sure would be sweet!

@KyleAMathews
Copy link

+1

4 similar comments
@mathiasschopmans
Copy link

👍

@LukeAskew
Copy link

+1

@Tims101
Copy link

Tims101 commented Aug 11, 2015

👍

@michael-lawrence
Copy link

👍

@axwell
Copy link

axwell commented Sep 5, 2015

No news on this ?

@avesus
Copy link

avesus commented Sep 7, 2015

👍

@smarts
Copy link

smarts commented Sep 19, 2015

I got this working locally (as an always-on feature, not configurable) by modifying http-server.js:

  before.push(ecstatic({
    gzip: true, // HACK: I ADDED THIS LINE!
    root: this.root,
    cache: this.cache,
    showDir: this.showDir,
    autoIndex: this.autoIndex,
    defaultExt: this.ext,
    handleError: typeof options.proxy !== 'string'
  }));

ecstatic will check if the accept-encoding header allows compression, and if present will look for a file that matches the requested file name with '.gz' at the end. For example:
this request: http://example.com/foo.css
with this header: Accept-Encoding: gzip, deflate, sdch
will look for a file called foo.css.gz and will serve it w/ the Content-Encoding: gzip HTTP header if it exists

@mydearxym
Copy link

+10

@hanai
Copy link

hanai commented Jan 23, 2016

It't really useful.

@tomkel
Copy link

tomkel commented Mar 4, 2016

+1!

@derhuerst
Copy link

Please use the reaction feature to express you'd like to have this feature.

@PatrickJS
Copy link

+1

@mattlavallee
Copy link

doing an npm install of http-server doesn't seem to pull in the gzip property event after an npm cache clean. Is this feature available in the npm package yet?

@derhuerst
Copy link

Is this feature available in the npm package yet?

Nope. npm info http-server gitHead says the published git commit is 1a8552c5e028bd5500027ee940111133927a4e94. 1a8552c is behind b456b77, which added gzip support.

@golopot
Copy link

golopot commented Oct 8, 2018

For what I understand the current --gzip option requires you to produce something.ext.gz by yourself. But what I want is a option that does the compression on the fly, like the express middleware app.use(compression()), just plug in one line and no hassle.

@BigBlueHat
Copy link
Member

@golopot right now, I'd say that on-the-fly compression is "out of scope" for a static web server--which should really just transmit content with minimal involvement. If you'd still like to discuss it, though, please file a separate issue. Thanks!

@WickyNilliams
Copy link
Author

To be clear, on-the-fly compression was exactly what I wanted when i originally opened this issue

@BigBlueHat
Copy link
Member

Good to know @WickyNilliams. At this point, I don't plan on going beyond what's "underneath" in the form of node-ecstatic's support https://github.com/jfhbrook/node-ecstatic#optsgzip

There are few things we're adding here, but mostly I'm wanting to continue to build up from the node-ecstatic foundation. Any sort of server-side content processing would be out-of-scope in that case.

@smarts
Copy link

smarts commented Oct 10, 2018

@BigBlueHat i wasn't necessarily looking for on-the-fly compression. As noted in my previous comment
#56 (comment)
i got it working w/ a hack, but i'd like this to be supported by the server's options instead of having to hack it myself. Can it be added as an option?

@BigBlueHat
Copy link
Member

@smarts it's been an option since 0.10.0 was released https://github.com/indexzero/http-server/releases/tag/0.10.0 😄 If you need something more, perhaps open a new issue so we can discuss that there rather than on this closed issue.

@smarts
Copy link

smarts commented Oct 10, 2018

Doh! I now see the pull request that references this issue. Thanks for being patient w/ me @BigBlueHat 😅

@Viyozc
Copy link

Viyozc commented Jun 12, 2019

+100

@Nashorn
Copy link

Nashorn commented Jul 21, 2020

Seriously, don't understand how hard on-the-fly compression can be, in just a few lines:

var zlib = require('zlib');

pathName = url.parse(request.url).pathname;
var fp = __dirname+"/../.."+pathName; //custom patthing, ignore

var readStream = fs.createReadStream(fp);
readStream.on('open', function (res) {
response.writeHead(200, { 'content-encoding': 'gzip' });
readStream.pipe(zlib.createGzip()).pipe(response);
});

@thornjad
Copy link
Member

@Nashorn you're more than welcome to turn your suggestion into a pull request!

@Nashorn
Copy link

Nashorn commented Sep 15, 2020

It's not clear from looking at http-server.js, where I would integrate the above solution which does dynamic gzip compression on responses. I found this area, but not even sure where/how to plug in.

var serverOptions = {
    before: before,
    headers: this.headers,
    onError: function (err, req, res) {
      if (options.logFn) {
        options.logFn(req, res, err);
      }

      res.end();
    }
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.