goStatic icon indicating copy to clipboard operation
goStatic copied to clipboard

Custom headers don't apply to directory indexes

Open KoltesDigital opened this issue 4 years ago • 3 comments

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.

KoltesDigital avatar Apr 13 '21 13:04 KoltesDigital

Hi @KoltesDigital!

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

PierreZ avatar Apr 15 '21 08:04 PierreZ

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.

KoltesDigital avatar Apr 15 '21 08:04 KoltesDigital

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 😄

PierreZ avatar Apr 21 '21 07:04 PierreZ