Skip to content

Commit fed98f2

Browse files
authored
Merge pull request http-party#293 from SteveVanOpstal/master
Add ecstatic's gzip mode
2 parents 1a8552c + b456b77 commit fed98f2

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ This will install `http-server` globally so that it may be run from the command
4444

4545
`-i` Display autoIndex (defaults to 'True')
4646

47+
`-g` or `--gzip` When enabled (defaults to 'False') it will serve `./public/some-file.js.gz` in place of `./public/some-file.js` when a gzipped version of the file exists and the request accepts gzip encoding.
48+
4749
`-e` or `--ext` Default file extension if none supplied (defaults to 'html')
4850

4951
`-s` or `--silent` Suppress log messages from output

bin/http-server

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ if (argv.h || argv.help) {
2222
' -a Address to use [0.0.0.0]',
2323
' -d Show directory listings [true]',
2424
' -i Display autoIndex [true]',
25+
' -g --gzip Serve gzip files when possible [false]',
2526
' -e --ext Default file extension if none supplied [none]',
2627
' -s --silent Suppress log messages from output',
2728
' --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header',
@@ -96,6 +97,7 @@ function listen(port) {
9697
cache: argv.c,
9798
showDir: argv.d,
9899
autoIndex: argv.i,
100+
gzip: argv.g || argv.gzip,
99101
robots: argv.r || argv.robots,
100102
ext: argv.e || argv.ext,
101103
logFn: logger.request,

lib/http-server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function HttpServer(options) {
4646
this.cache = options.cache === undefined ? 3600 : options.cache; // in seconds.
4747
this.showDir = options.showDir !== 'false';
4848
this.autoIndex = options.autoIndex !== 'false';
49+
this.gzip = options.gzip === true;
4950
this.contentType = options.contentType || 'application/octet-stream';
5051

5152
if (options.ext) {
@@ -97,6 +98,7 @@ function HttpServer(options) {
9798
showDir: this.showDir,
9899
autoIndex: this.autoIndex,
99100
defaultExt: this.ext,
101+
gzip: this.gzip,
100102
contentType: this.contentType,
101103
handleError: typeof options.proxy !== 'string'
102104
}));

0 commit comments

Comments
 (0)