diff --git a/src/middleware/serve-static/index.test.ts b/src/middleware/serve-static/index.test.ts index 585008ca..3f0c493f 100644 --- a/src/middleware/serve-static/index.test.ts +++ b/src/middleware/serve-static/index.test.ts @@ -143,6 +143,7 @@ describe('Serve Static Middleware', () => { expect(res.status).toBe(200) expect(res.headers.get('Content-Encoding')).toBe('br') expect(res.headers.get('Vary')).toBe('Accept-Encoding') + expect(res.headers.get('Content-Type')).toBe('application/octet-stream') expect(await res.text()).toBe('Hello in static/hello.unknown.br') }) diff --git a/src/middleware/serve-static/index.ts b/src/middleware/serve-static/index.ts index 6c45d61a..d9cdfbc0 100644 --- a/src/middleware/serve-static/index.ts +++ b/src/middleware/serve-static/index.ts @@ -99,13 +99,8 @@ export const serveStatic = ( } if (content) { - const mimeType = options.mimes - ? getMimeType(path, options.mimes) ?? getMimeType(path) - : getMimeType(path) - - if (mimeType) { - c.header('Content-Type', mimeType) - } + const mimeType = (options.mimes && getMimeType(path, options.mimes)) || getMimeType(path) + c.header('Content-Type', mimeType || 'application/octet-stream') if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) { const acceptEncodingSet = new Set(