Skip to content

Conversation

Jarred-Sumner
Copy link
Collaborator

@Jarred-Sumner Jarred-Sumner commented Oct 6, 2024

What does this PR do?

Extremely WIP.

Rewrite node:http to not use Request & Response for Bun.serve

Introduce a new internal API that currently looks like this and may change at any point:

import { serve } from "bun";

serve({
  port: 3002,

  onNodeHTTPRequest(server, url: string, method: string, headers: Record<string, string>, rawHeaders: string[], handle, hasBody: boolean) {
    handle.writeHead(200, { "Content-Type": "text/plain" });
    handle.end("Hello World");
  },
});

This does not replace fetch in Bun.serve()

How did you verify your code works?

it doesn't really work yet. We aren't emitting socket.

@robobun
Copy link
Collaborator

robobun commented Oct 6, 2024

@Jarred-Sumner, your commit 1a59948 has some failures in #7923

@kravetsone
Copy link

will it be available for the first time through the flag? it sounds dangerous if suddenly the insides change so much

@Jarred-Sumner
Copy link
Collaborator Author

@kravetsone i agree dangerous, but we have far better test coverage than we used to.

@kravetsone
Copy link

@kravetsone i agree dangerous, but we have far better test coverage than we used to.

It's great
But it maybe more painful for developers which don't pin bun docker image version

Test coverage can't find all bugs

@Jarred-Sumner Jarred-Sumner mentioned this pull request Oct 7, 2024
67 tasks
@huseeiin
Copy link
Contributor

huseeiin commented Oct 9, 2024

super cool

@huseeiin
Copy link
Contributor

there was a trick in bun to get the Request object (from a symbol) in node:http:

import { createServer } from "http";

createServer(async (req, res) => {
    const request: Request = req[Object.getOwnPropertySymbols(req)[3]];

    const json = await request.json().catch(() => null);

    res.end(json);
}).listen(3000);

does this PR mean this is no longer gonna be possible?

@huseeiin
Copy link
Contributor

so this idea is completely dismissed or just the pr?

@mtsewrs
Copy link

mtsewrs commented Jun 24, 2025

As a library author this functional approach would be great to have imo since it has less overhead and also more compatible with node and i guess uws. Hope you reconsider ❤️

@Jarred-Sumner
Copy link
Collaborator Author

so this idea is completely dismissed or just the pr?

this PR was very stale. we shipped this in Bun v.1.2.6 where we made Express 9% faster, with the actual PR landing the changes in #17093

@Jarred-Sumner Jarred-Sumner deleted the jarred/uws branch June 24, 2025 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants