0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

fix(serve-static): use application/octet-stream if the mime type is not detected (#3415)

This commit is contained in:
Taku Amano 2024-09-17 10:07:36 +09:00 committed by GitHub
parent 0edb243a74
commit 27a57c3f67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 7 deletions

View File

@ -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')
})

View File

@ -99,13 +99,8 @@ export const serveStatic = <E extends Env = Env>(
}
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(