PierreZ / goStatic

A really small static web server for Docker
GNU General Public License v2.0
395 stars 77 forks source link

Custom headers don't apply to directory indexes #42

Open KoltesDigital opened 3 years ago

KoltesDigital commented 3 years ago

Hi, thanks for your image.

I've tried to use the custom headers feature. They work for files, but not for directories, although requesting a directory leads to its index.html. To be more precise, a config entry with "path": "*", "fileExtension": "html" does apply when requesting /path/index.html, but does not for /path, although the response body is the same.

The code at https://github.com/PierreZ/goStatic/blob/131f4922cd4f1a8038b04f7e74f27a8c0d3290fc/customHeaders.go#L88 shows that the middleware applies to the URL. Would it be possible to apply to the resolved file instead?

As a side note, I believe path + fileExtension should be superseded by a path glob or a regex, which is more powerful, and is actually not more complex. For instance, a rule with glob /**/ or regex \/$ would apply to any directory, and a rule with glob /**/*.css (or maybe even *.css) or regex \.css$ would apply to any CSS file.

PierreZ commented 3 years ago

Hi @KoltesDigital!

You are welcome to open a PR if you want to contribute to goStatic.

KoltesDigital commented 3 years ago

I'm willing to! I saw not-replied issues and wasn't sure you were still maintaining the project.

In order not to work for nothing, will you consider a PR that takes indexes into account, and I think it's better to open another one to add glob/regex to rules? I would not remove the current path + fileExtension to stay backward compatible.

PierreZ commented 3 years ago

I'm willing to! I saw not-replied issues and wasn't sure you were still maintaining the project.

Oups, I missed some notifications it seems.

In order not to work for nothing, will you consider a PR that takes indexes into account, and I think it's better to open another one to add glob/regex to rules? I would not remove the current path + fileExtension to stay backward compatible.

👍👍 Looking forward for those two PRs 😄