diff --git a/pkg/web/webui_blob.go b/pkg/web/webui_blob.go index 3c45469cc85ff0914228aac6064ecb6062e00bfd..89f92d3127f257e1714acb267ed5db416fbe8b16 100644 --- a/pkg/web/webui_blob.go +++ b/pkg/web/webui_blob.go @@ -3,6 +3,7 @@ package web import ( "bytes" "html/template" + "mime" "net/http" "path/filepath" "strings" @@ -166,8 +167,16 @@ func repoBlobRaw(w http.ResponseWriter, r *http.Request) { return } - w.Header().Set("Content-Type", "text/plain; charset=utf-8") - w.Write(content) + contentType := mime.TypeByExtension(filepath.Ext(path)) + if contentType == "" { + contentType = http.DetectContentType(content) + } + if strings.HasPrefix(contentType, "text/") && !strings.Contains(contentType, "charset") { + contentType += "; charset=utf-8" + } + + w.Header().Set("Content-Type", contentType) + _, _ = w.Write(content) } // isBinaryContent detects if file content is binary using a simple heuristic.