mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-13 09:24:02 +02:00
fix favicon content type
This commit is contained in:
parent
49da8a31d2
commit
4e7bd3579b
1 changed files with 14 additions and 9 deletions
|
@ -67,6 +67,17 @@ func (res *fetchResult) OK() bool {
|
||||||
return res.icon != nil
|
return res.icon != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (res *fetchResult) ContentType() string {
|
||||||
|
if res.contentType == "" {
|
||||||
|
if bytes.HasPrefix(res.icon, []byte("<svg")) {
|
||||||
|
return "image/svg+xml"
|
||||||
|
} else {
|
||||||
|
return "image/x-icon"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res.contentType
|
||||||
|
}
|
||||||
|
|
||||||
// GetFavIcon returns the favicon of the route
|
// GetFavIcon returns the favicon of the route
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
|
@ -98,7 +109,7 @@ func GetFavIcon(w http.ResponseWriter, req *http.Request) {
|
||||||
http.Error(w, fetchResult.errMsg, fetchResult.statusCode)
|
http.Error(w, fetchResult.errMsg, fetchResult.statusCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", fetchResult.contentType)
|
w.Header().Set("Content-Type", fetchResult.ContentType())
|
||||||
U.WriteBody(w, fetchResult.icon)
|
U.WriteBody(w, fetchResult.icon)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -129,7 +140,7 @@ func GetFavIcon(w http.ResponseWriter, req *http.Request) {
|
||||||
http.Error(w, result.errMsg, result.statusCode)
|
http.Error(w, result.errMsg, result.statusCode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", result.contentType)
|
w.Header().Set("Content-Type", result.ContentType())
|
||||||
U.WriteBody(w, result.icon)
|
U.WriteBody(w, result.icon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,13 +199,7 @@ func loadIconCache(key string) *fetchResult {
|
||||||
Str("key", key).
|
Str("key", key).
|
||||||
Msg("icon found in cache")
|
Msg("icon found in cache")
|
||||||
|
|
||||||
var contentType string
|
return &fetchResult{icon: icon}
|
||||||
if bytes.HasPrefix(icon, []byte("<svg")) {
|
|
||||||
contentType = "image/svg+xml"
|
|
||||||
} else {
|
|
||||||
contentType = "image/x-icon"
|
|
||||||
}
|
|
||||||
return &fetchResult{icon: icon, contentType: contentType}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue