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

Send a correct Content-Type for device icons #41

Merged
merged 1 commit into from
May 28, 2017

Conversation

h31
Copy link
Contributor

@h31 h31 commented May 28, 2017

Currently DMS sends "Content-Type: text/plain" for device icon requests which may confuse some clients. The reason is that http.ServeContent can't deduce a correct type and uses a default value.

@@ -813,6 +813,11 @@ func (server *Server) initMux(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/", pprof.Index)
for i, di := range server.Icons {
mux.HandleFunc(fmt.Sprintf("%s/%d", deviceIconPath, i), func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", di.Mimetype)
ext, _ := mime.ExtensionsByType(di.Mimetype)
if ext != nil && len(ext) > 0 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's okay to call len on a nil slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, thanks.

if v is nil, len(v) is zero.

w.Header().Set("Content-Type", di.Mimetype)
ext, _ := mime.ExtensionsByType(di.Mimetype)
if ext != nil && len(ext) > 0 {
w.Header().Set("Ext", strings.TrimPrefix(ext[0], "."))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is what the Ext header is for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Ext" header is only mentioned here. Looks like it always should be empty, and it is completely unrelated to the file extension.
I set it while debugging issue #40. It just seemed strange to me that the header is empty.
Thank you for removing these lines youself.

@anacrolix anacrolix merged commit 6274787 into anacrolix:master May 28, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants