use HasSuffix to determine content type

This commit is contained in:
Antoni Sawicki 2024-07-01 23:15:18 -07:00
parent 9a0e5809c1
commit 3e8f109edd

6
wrp.go
View File

@ -537,11 +537,11 @@ func imgServer(w http.ResponseWriter, r *http.Request) {
defer delete(img, r.URL.Path)
}
switch {
case strings.HasPrefix(r.URL.Path, ".gif"):
case strings.HasSuffix(r.URL.Path, ".gif"):
w.Header().Set("Content-Type", "image/gif")
case strings.HasPrefix(r.URL.Path, ".png"):
case strings.HasSuffix(r.URL.Path, ".png"):
w.Header().Set("Content-Type", "image/png")
case strings.HasPrefix(r.URL.Path, ".jpg"):
case strings.HasSuffix(r.URL.Path, ".jpg"):
w.Header().Set("Content-Type", "image/jpeg")
}
w.Header().Set("Content-Length", strconv.Itoa(len(imgBuf.Bytes())))