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

Small differences with http.FileServer, should be in the readme? #16

Closed
bezineb5 opened this issue Jul 10, 2020 · 1 comment
Closed

Comments

@bezineb5
Copy link
Contributor

Thanks for the excellent library!
Two small things worth signalling which make it not a perfect drop-in:

  • In case the mime type cannot be determined from the extension by the mime.TypeByExtension method, ServeContent will try to infer from the actual file content: https://golang.org/src/net/http/fs.go?s=4932:5036#L198 so it will return a type like "application/x-gzip", whereas http.FileServer would have return "text/plain" for a YAML file, for example. This can lead to bugs, for example when trying to use the Swagger UI.
    => workaround: register such non-standard types (there's actually no official mime type for YAML):
    mime.AddExtensionType(".yaml", "application/x-yaml")
  • http.FileServer can find a file requested as "static/test.html" (for example when using http.StripPrefix) whereas gzipped.FileServer requires the leading "/"

Thanks!
Ben

@bezineb5
Copy link
Contributor Author

My bad for the 2nd difference, the issue is with the withIndexHTML helper, in the case "" is requested. I'll do a quick PR.

bezineb5 referenced this issue Jul 10, 2020
When leading / is stripped, withIndexHTML receives "" as URL path and doesn't handle it as "/".
@lpar lpar closed this as completed Jul 11, 2020
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

No branches or pull requests

2 participants