http-party / http-server

a simple zero-configuration command-line http server
MIT License
13.42k stars 1.48k forks source link

Serve compressed files if already exist #852

Open De-Panther opened 1 year ago

De-Panther commented 1 year ago

If file is already compressed (ends with .gz or .br), no need to add those file extensions. Sometime files are already compressed and needs to serve with the correct header. In some cases engines like Unity output some of the files as compressed and others not.

This change allows to serve already compressed files even if Serve GZIP Files or Serve Brotli Files are false.

I'm not sure how to write a test, or if this change should be documented. It seems to me like an obvious outcome when serving a .gz or .br file. So I think it's a bug fix rather than a feature or a change in a feature.

Relevant issues

Resolves #844 Resolves #780

Contributor checklist
Maintainer checklist
De-Panther commented 11 months ago

Apparently there were already tests for gzip and brotli, and my first commit broke the Content-Type tests. I moved the defaultType to the start of the process right after the options are parsed. Also moved the MIME lookup to right after we get the file, which made redundant the special lookup for compressed files.

Some unrelated CLI tests don't work for me both on master and on this PR.

@thornjad is there something else I should do for this PR to be approved? Thanks