Skip to content

413 HTTP Responses do not include a Date header #27512

@CMTegner

Description

@CMTegner

What version of Bun is running?

1.3.10+30e609e08

What platform is your computer?

Darwin 25.3.0 arm64 arm

What steps can reproduce the bug?

import { expect, test } from "bun:test";

test("413 responses should include a Date header", async () => {
    using server = Bun.serve({
        port: 0,
        maxRequestBodySize: 1,
        fetch() {
            return new Response("Hello Bun");
        },
    });
    const res = await fetch({
        url: `http://localhost:${server.port}/`,
        method: "POST",
        body: "12",
    });
    expect(res.status).toBe(413);
    expect(res.headers.get("date")).not.toBeNull();
});

What is the expected behavior?

$ bun test ./repro.ts
bun test v1.3.10 (30e609e0)

repro.ts:
✓ 413 responses should include a Date header [10.27ms]

 1 pass
 0 fail
 2 expect() calls
Ran 1 test across 1 file. [127.00ms]

What do you see instead?

$ bun test ./repro.ts
bun test v1.3.10 (30e609e0)

repro.ts:
12 |         url: `http://localhost:${server.port}/`,
13 |         method: "POST",
14 |         body: "12",
15 |     });
16 |     expect(res.status).toBe(413);
17 |     expect(res.headers.get("date")).not.toBeNull();
                                             ^
error: expect(received).not.toBeNull()

Received: null

      at <anonymous> (/<redacted>/repro.ts:17:41)
✗ 413 responses should include a Date header [11.93ms]

 0 pass
 1 fail
 2 expect() calls
Ran 1 test across 1 file. [115.00ms]

Additional information

According to the spec:

An origin server with a clock (as defined in Section 5.6.7) MUST generate a Date header field in all 2xx (Successful), 3xx (Redirection), and 4xx (Client Error) responses, and MAY generate a Date header field in 1xx (Informational) and 5xx (Server Error) responses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions