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 (#201)
  • Loading branch information
usualoma authored Sep 21, 2024
1 parent 64a4a91 commit e64721a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/serve-static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ export const serveStatic = (options: ServeStaticOptions = { root: '' }): Middlew
await options.onFound?.(path, c)

const mimeType = getMimeType(path)
if (mimeType) {
c.header('Content-Type', mimeType)
}
c.header('Content-Type', mimeType || 'application/octet-stream')

if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
const acceptEncodingSet = new Set(
Expand Down
3 changes: 2 additions & 1 deletion test/serve-static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ describe('Serve Static Middleware', () => {
it('Should handle an extension less files', async () => {
const res = await request(server).get('/static/extensionless')
expect(res.status).toBe(200)
expect(res.text).toBe('Extensionless')
expect(res.headers['content-type']).toBe('application/octet-stream')
expect(res.body.toString()).toBe('Extensionless')
})

it('Should return a pre-compressed zstd response - /static-with-precompressed/hello.txt', async () => {
Expand Down

0 comments on commit e64721a

Please sign in to comment.