Closed thornjad closed 6 years ago
@thornjad pretty sure adding fs.stat
calls before responding will make ecstatic slower, regardless of the optimized encoding. Perhaps this should be opt-in?
I believe the stat call currently happens with gzip, fwiw
Yes, I modeled it on the way gzip was already implemented, and only making the fs.stat
calls when necessary. If there's a faster way to do the same thing, however, I'm all in.
possibly relevant https://github.com/jfhbrook/node-ecstatic/pull/195/files
How does this look to everyone? Are there any objections?
No immediate concerns, but I'd like to take a closer look and kick the tires on this just the same
Documentation added! Thank you for reviewing!
Hey, so uh, after merging this I get multiple test fails on Windows @thornjad , can you reproduce (on any platform, maybe not win-specific) ? I can track down this failure but not right now, maybe in the next day or two, but knowing if it's just me will help.
test/compression.js ................................. 16/18
serves gzip-encoded file when brotli not accepted
not ok should be equal
+++ found
--- wanted
-"gzip"
+[null]
compare: ===
at:
line: 91
column: 9
file: test/compression.js
type: Request
function: request.get
method: _callback
stack: |
Request.request.get [as _callback] (test/compression.js:91:9)
Request.self.callback (node_modules/request/request.js:185:22)
Request.<anonymous> (node_modules/request/request.js:1161:10)
IncomingMessage.<anonymous> (node_modules/request/request.js:1083:12)
source: |
t.equal(res.headers['content-encoding'], 'gzip');
serves gzip-encoded file when brotli not enabled
not ok should be equal
+++ found
--- wanted
-"gzip"
+[null]
compare: ===
at:
line: 121
column: 9
file: test/compression.js
type: Request
function: request.get
method: _callback
stack: |
Request.request.get [as _callback] (test/compression.js:121:9)
Request.self.callback (node_modules/request/request.js:185:22)
Request.<anonymous> (node_modules/request/request.js:1161:10)
IncomingMessage.<anonymous> (node_modules/request/request.js:1083:12)
source: |
t.equal(res.headers['content-encoding'], 'gzip');
Very weird. Yes I can reproduce this on Linux, I'm going to see if I get the same on an entirely fresh install on Windows. The weird part is that I don't get the same test failures on my fork.
ok word so it's probably not a windows-specific issue. You don't have to try to repro on windows specifically in that case, imo.
and yeah, frickin' weird right??
Ready for a new kicker? I just pulled master into the master on my fork, and? No error. I'm going to try to investigate this now if I have enough time.
wondering if it has to do with line endings
y'know \n vs \r\n, git pulls some shenanigans on text files to make them happy this way
also, check for accidentally uncommitted things, maybe you have a delta or a new file somewhere
Nothing uncommitted. I've seen line endings messed up in git before, and it doesn't look like that's the case, but I don't know how to check for sure.
I'm not 100% on that either, maybe a regexp search for \n vs \r\n ? or we use a binary upload/download site and run diff?
With some experimentation, it looks like in those two test cases, where brotli is not accepted and where brotli is not enabled, it isn't falling back on gzip like it should. For example, when I go to test/public/brotli in firefox (which doesn't support brotli without https), I get the uncompressed index file.
As for differences, I used cat lib/ecstatic.js | grep "^M"
and found nothing, and diff
and comm
find no differences with my fork. I can look more tomorrow, I really don't know what's up but really want to find out.
Possible there's a race condition?
I've found the problem, and it's frustratingly simple! Both of those tests are attempting to serve test/public/brotli/index.html.gz
, which exist in my local fork. However, *.gz
is in the .gitignore
, so those local files were never even tracked. Since I added the entire test/public/brotli
directory at once, I didn't even notice. Getting rid of that line in the .gitignore
fixes it all!
Because of #230, how should I submit this change? Should it be a new PR?
let's try this:
A little "hold my beer" but I think that'll have the correct behavior in terms of playing nice w/ git and github.
You can pull this branch locally from my upstream, then cherry-pick the fix in and it should do the right thing
Published 3.3.0, cheers!
Brotli encoding is a relatively new compression algorithm which may be better than gzip, and is supported by all major browsers according to Wikipedia. This patch adds support for ecstatic to serve brotli-encoded files (using the .br extension) if the browser supports it.
Some things to note: