http-server
http-server copied to clipboard
Missing HTTP Response Header "Content-Encoding: gzip"
-g option will enable content-type: application/gzip; charset=utf-8
but this is not enough, it has to have "Content-Encoding: gzip" also in response header
here is an example of error message when attempting to serve gzip content:
Did a little investigating, the issue is in this block of code shown below, the test for file === gzippedFile always fails. I replaced the test with if (file.includes(".gz")) and it works correctly for me now. This is just a hack and probably not the intended way things should work but it gets it done for now. cheers.
if (file === gzippedFile) { // is .gz picked up
res.setHeader('Content-Encoding', 'gzip');
// strip gz ending and lookup mime type
contentType = mime.lookup(path.basename(file, '.gz'), defaultType);
} else if (file === brotliFile) { // is .br picked up
res.setHeader('Content-Encoding', 'br');
// strip br ending and lookup mime type
contentType = mime.lookup(path.basename(file, '.br'), defaultType);
}
Just a little added thought. Perhaps the script checks for a regular file and then sees if there is also a .gz file version of the same file? In my case there is only a .gz file, no regular file exists. So I think it is attempting to see if there is a .gz.gz file which of course will fail, when in fact it should just serve the .gz file without checking if there is a gz and a non-gz file.
This issue has been inactive for 180 days
Did a little investigating, the issue is in this block of code shown below, the test for file === gzippedFile always fails. I replaced the test with if (file.includes(".gz")) and it works correctly for me now. This is just a hack and probably not the intended way things should work but it gets it done for now. cheers.
if (file === gzippedFile) { // is .gz picked up res.setHeader('Content-Encoding', 'gzip'); // strip gz ending and lookup mime type contentType = mime.lookup(path.basename(file, '.gz'), defaultType); } else if (file === brotliFile) { // is .br picked up res.setHeader('Content-Encoding', 'br'); // strip br ending and lookup mime type contentType = mime.lookup(path.basename(file, '.br'), defaultType); }
Thanks! This worked for me, replacing the "if (file === gzippedFile) {" line (location: http-server\lib\core\index.js)
Bump. Can we get that fix into the repo ? This also fixes the problem of serving compressed unity player WebGL builds via node.js Thanks !
Bump. Can we get that fix into the repo ? This also fixes the problem of serving compressed unity player WebGL builds via node.js Thanks !
I've started a pull request but it probably still needs some work #834
Bump. Would be great to get the fix pulled into the repo. Thanks.
-g option will enable content-type: application/gzip; charset=utf-8 but this is not enough, it has to have "Content-Encoding: gzip" also in response header here is an example of error message when attempting to serve gzip content:
Where can you find this file to change the if?