fix #4485, close #4487: audio/mpeg for .mp3

This commit is contained in:
Evan Wallace
2026-08-07 15:21:58 -04:00
parent a647c15e37
commit bd7541f128
3 changed files with 8 additions and 1 deletions
+4
View File
@@ -2,6 +2,10 @@
## Unreleased
* Force `.mp3` files to use the `audio/mpeg` MIME type ([#4485](https://github.com/evanw/esbuild/issues/4485))
MIME type detection for esbuild's data URLs uses Go's built-in MIME type detection, which is based on the [MIME sniffing standard](https://mimesniff.spec.whatwg.org/). This works correctly for MP3 files that start with the byte sequence `ID3`, which is commonly the case. However, it's possible to construct valid MP3 files that do not start with `ID3`, and that perhaps Go's built-in MIME type detection doesn't implement the "Signature for MP3 without ID3" part of the algorithm. This results in some `.mp3` files incorrectly using the `application/octet-stream` MIME type instead of `audio/mpeg`. With this release, esbuild will now always use the `audio/mpeg` MIME type for files ending in `.mp3`.
* Add a new TypeScript syntax warning
TypeScript 7 turned some previously-valid TypeScript syntax into a syntax error because it was confusing. TypeScript 6 accepts `1 + 2 as number * 3` as valid syntax but confusingly converts it to `(1 + 2) * 3` instead of the more intuitive conversion to `1 + (2 * 3)`. This syntax is now an error in TypeScript 7+. With this release, esbuild will now warn about the use of this syntax:
+3
View File
@@ -24,6 +24,9 @@ var builtinTypesLower = map[string]string{
".svg": "image/svg+xml",
".webp": "image/webp",
// Audio
".mp3": "audio/mpeg",
// Fonts
".eot": "application/vnd.ms-fontobject",
".otf": "font/otf",
+1 -1
View File
@@ -350,7 +350,7 @@ func (h *apiHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
if contentType := helpers.MimeTypeByExtension(h.fs.Ext(file.absPath)); contentType != "" {
res.Header().Set("Content-Type", contentType)
} else {
res.Header().Set("Content-Type", "application/octet-stream")
res.Header().Set("Content-Type", http.DetectContentType(fileBytes))
}
if isRange {
res.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", begin, end-1, fileContentsLen))