oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.61k stars 2.72k forks source link

Missing Date header in Bun.file response #11427

Closed 7f8ddd closed 2 months ago

7f8ddd commented 4 months ago

What version of Bun is running?

1.1.10-canary.1+34b02ada1

What platform is your computer?

Linux 6.8.0-31-generic x86_64 x86_64

What steps can reproduce the bug?

Bun.serve({
  fetch(req: Request) {
    const file = Bun.file("test.css");

    // The response *will* include the Date header.
    return new Response(file, {
      headers: {
        "hello-world": "yes",
      },
    });

    // The response *will not* include the Date header.
    return new Response(file);
  },

  port: 8080,
});

Additional information

The RFC 7231 for HTTP/1.1 states that the Date header should always be included except for in these cases:

If the response status code is 100 (Continue) or 101 (Switching Protocols). If the response has no content-body and the request method was HEAD."

Where it's being added: https://github.com/oven-sh/bun/blob/912bccb6243bbc169c0d92e23dc1be7f01e44fba/packages/bun-uws/src/HttpResponse.h#L77

It seems like the Bun.file path with no additional headers is stripping/bypassing that code.

bogeychan commented 4 months ago

On Windows (bun --version 1.1.10), both responses will include the Date header