Skip to content

Custom HTTP methods via Bun.serve() #6556

Open

Description

@phillip-elm

What is the problem this feature would solve?

Using custom methods not defined in http/method.zig cause Bun to return an empty response without invoking the fetch function.

For example:

// example.ts
Bun.serve({
  port: 8080,
  fetch(req) { 
    console.log(req.method);
    return new Response(req.method);
  }
})
bun run example.ts
curl -X MYCUSTOMMETHOD http://127.0.0.1:8080
curl: (52) Empty reply from server

Edit and further considerations

After further reading and experimentation, it seems that Node.js has a list of supported verbs that cannot be extended either. If requests come in that do not fit within the supported list, they are dropped with a 400 Bad Request response.

I'm not championing custom HTTP verbs as a good design idea - but there are circumstances where older services cannot be cleanly ported to Bun (or Node.js for that matter) due to this limitation.

What is the feature you are proposing to solve the problem?

  1. That custom request methods are allowed, and/or;
  2. That the response to an unsupported method be more graceful. As noted in my edit above, Node.js sends a 400 Bad Request error before closing the connection.

Activity

  1. added
    enhancement
    on Oct 17, 2023
  2. changed the title [-]Allow use of custom HTTP methods via Bun.serve()[/-] [+]Custom HTTP methods via Bun.serve()[/+] on Oct 17, 2023
  3. added
    bun.js
    on Oct 17, 2023
  4. added
    bun:serve
    and removed
    bun.js
    on Jun 18, 2025
  5. removed their assignment
    on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bun:serveenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions