Implement common file server to return consistent Content-Type#191
Merged
brian-brazil merged 2 commits intoprometheus:masterfrom May 7, 2019
Merged
Implement common file server to return consistent Content-Type#191brian-brazil merged 2 commits intoprometheus:masterfrom
brian-brazil merged 2 commits intoprometheus:masterfrom
Conversation
When `/etc/mime.types` has a unusual mime type, Content-Type of response becomes the type and you may get unexpected result. This server returns consistent Content-Type header for js and css files Signed-off-by: mrasu <m.rasu.hitsuji@gmail.com>
server/static_file_server.go
Outdated
| "path/filepath" | ||
| ) | ||
|
|
||
| func StaticFileServer(root http.FileSystem) http.Handler { |
Member
There was a problem hiding this comment.
You can even remove the internal staticFileHandler struct by using a http.HandlerFunc:
func StaticFileServer(root http.FileSystem) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
fileExt := filepath.Ext(r.URL.Path)
switch fileExt {
case ".js":
w.Header().Set("Content-Type", "application/javascript")
case ".css":
w.Header().Set("Content-Type", "text/css")
}
http.FileServer(root).ServeHTTP(w, r)
},
)
}
brian-brazil
reviewed
May 7, 2019
server/static_file_server.go
Outdated
| case ".js": | ||
| w.Header().Set("Content-Type", "application/javascript") | ||
| case ".css": | ||
| w.Header().Set("Content-Type", "text/css") |
Contributor
There was a problem hiding this comment.
Should we add images too?
Contributor
Author
There was a problem hiding this comment.
Thanks! I add png, jpg, and gif
Signed-off-by: mrasu <m.rasu.hitsuji@gmail.com>
Contributor
|
👍 |
Contributor
|
Thanks! |
Member
|
@brian-brazil does this justify tagging a new release? It would help to use this feature in other repos. |
Contributor
|
Sure, done. We can release this repo anytime, it's pretty light. |
alanprot
pushed a commit
to alanprot/common
that referenced
this pull request
Mar 15, 2023
* Make signal-handling by Server configurable. * Fixed unrelated lint warnings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
/etc/mime.typeshas an unusual mime type, Content-Type of response becomes the type and you may get an unexpected result.This server returns consistent Content-Type header for js and css files
Signed-off-by: mrasu m.rasu.hitsuji@gmail.com