Skip to content

serveStatic: unable to override content-type header in onFound #225

@teidesu

Description

@teidesu

/subj

repro

  1. curl https://cataas.com/cat > static/meow

  2. run:

const app = new Hono()
app.use('/*', serveStatic({
  root: 'static',
  onFound: (path, ctx) => {
    ctx.res.headers.set('Content-Type', 'image/jpeg')
  }
})

serve(app)
  1. curl -I localhost:3000/meow

expected

Content-Type header is set to image/jpeg

actual

Content-Type header is set to application/octet-stream because there is no extension

additional context

https://github.com/honojs/node-server/blob/main/src/serve-static.ts#L108-L111 – onFound is called before the mime type is derived from the extension, so simply moving it a few lines down should solve this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions