Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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