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

Missing HTTP Response Header "Content-Encoding: gzip" #780

Open
GhostCore07 opened this issue Dec 27, 2021 · 8 comments · May be fixed by #852
Open

Missing HTTP Response Header "Content-Encoding: gzip" #780

GhostCore07 opened this issue Dec 27, 2021 · 8 comments · May be fixed by #852

Comments

@GhostCore07
Copy link

-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:
image

@GhostCore07
Copy link
Author

GhostCore07 commented Dec 27, 2021

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);
}

@GhostCore07
Copy link
Author

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.

@github-actions
Copy link

This issue has been inactive for 180 days

@github-actions github-actions bot added the stale label Jun 25, 2022
@Develobba
Copy link

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)

@github-actions github-actions bot removed the stale label Jul 23, 2022
@ostryhub
Copy link

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 !

@GhostCore07
Copy link
Author

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

@InvivoLuke
Copy link

Bump.
Would be great to get the fix pulled into the repo.
Thanks.

@Kbeanstudios
Copy link

Kbeanstudios commented Jan 9, 2023

-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: image

Where can you find this file to change the if?

@De-Panther De-Panther linked a pull request Feb 6, 2023 that will close this issue
8 tasks
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.

5 participants