Skip to content

Commit

Permalink
fix(serve-static): use application/octet-stream if the mime type is n…
Browse files Browse the repository at this point in the history
…ot detected (#3415)
  • Loading branch information
usualoma authored Sep 17, 2024
1 parent 0edb243 commit 27a57c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/middleware/serve-static/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

Expand Down
9 changes: 2 additions & 7 deletions src/middleware/serve-static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 27a57c3

Please sign in to comment.