Comments (29)
+1
from http-server.
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
from http-server.
Please use the reaction feature to express you'd like to have this feature.
from http-server.
@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.
from http-server.
+10
from http-server.
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.
from http-server.
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.
from http-server.
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);
});
from http-server.
+1
from http-server.
+1 would like this too
from http-server.
+1 This sure would be sweet!
from http-server.
+1
from http-server.
👍
from http-server.
+1
from http-server.
👍
from http-server.
👍
from http-server.
No news on this ?
from http-server.
👍
from http-server.
It't really useful.
from http-server.
+1!
from http-server.
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?
from http-server.
@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!
from http-server.
To be clear, on-the-fly compression was exactly what I wanted when i originally opened this issue
from http-server.
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.
from http-server.
@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?
from http-server.
Doh! I now see the pull request that references this issue. Thanks for being patient w/ me @BigBlueHat 😅
from http-server.
+100
from http-server.
@Nashorn you're more than welcome to turn your suggestion into a pull request!
from http-server.
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();
}
};
from http-server.
Related Issues (20)
- Static File Directory flag HOT 1
- 404 error on the page with param HOT 2
- index.html change but doesn't have any auto refreshing must to manual refresh HOT 4
- Proxy target request header not present HOT 1
- Bug Report HOT 1
- Do not open a new browser window if one is already open HOT 1
- RangeError: Invalid time value HOT 3
- --cors usage is incorrect in the documentation HOT 1
- How to let the json file (*.json) return response header: 'application/json', instead of 'application/json; charset=UTF-8' HOT 1
- OWASP vulnerability in dependency tree HOT 1
- i use it with termux,but i do not know how to upload file to termux HOT 1
- http-server runing on project root folder path without any reasons HOT 2
- {"message":"You are not authorized"} in GitHub Codespace HOT 2
- Support relative path prefixes (base in vite.config.js) HOT 2
- Need a maintainer? HOT 9
- Link not opening in Browser
- Add bandwidth limit parameter HOT 1
- Option -c is not working
- gz not served HOT 1
- qr code generator in termal HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-server.