h3 icon indicating copy to clipboard operation
h3 copied to clipboard

bun sets default `content-type` for Uint8Array

Open huseeiin opened this issue 5 months ago • 1 comments

Environment

using h3 v2 directly from repo "./src/index.ts" and bun 1.2.18

Reproduction

import { H3, serve } from "./src/index.ts";

const app = new H3();

app.get("/", (e) => {
  return new TextEncoder().encode("hello");
});

console.log(
  await fetch(serve(app).url!).then((r) => r.headers.get("content-type")),
);

Describe the bug

application/octet-stream is unexpected. when opening in a browser it downloads a file.

Additional context

in node it doesn't download and content-type is null

Logs


huseeiin avatar Jul 13 '25 11:07 huseeiin

export default {
  fetch(req) {
    return new Response(new TextEncoder().encode("hello"));
  },
};

Running this in bun > curl -v localhost:3000:

< HTTP/1.1 200 OK
< content-type: application/octet-stream

Running the same code in Deno, does not set content-type

Also running a normal Node.js server, does not sets content-type

new Server((req, res) => {
  res.end(new TextEncoder().encode("hello"));
}).listen(3000);

It is a Bun-specific behavior and has nothing to do with H3 or Srvx. I think we should report it in Bun as a bug and mismatching behavior with all other runtimes.

pi0 avatar Jul 13 '25 19:07 pi0