Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HTTP Server): can't set custom statusText #10266

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

coratgerl
Copy link
Contributor

@coratgerl coratgerl commented Apr 14, 2024

What does this PR do?

On node we can change the statusText in the Response. On Bun, Bun.serve and createServer from node:http only returns the default statusText define here https://github.com/oven-sh/bun/blob/main/src/bun.js/api/server.zig#L1039.

So actually the two following code doesn't change the statusText

Bun.serve({
  fetch(request) {
    return new Response(request.url, {
      statusText: "customStatusText",
    });
  },
  port: 0,
});
import { createServer } from 'node:http'

const server = createServer((req, res) => {
	res.writeHead(200, 'statusMessage')
	res.end('Hello World\n')
})

server.listen(3000)
  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote automated tests

@coratgerl coratgerl changed the title fix: custom statusText fix(HTTP Server): can't set custom statusText Apr 14, 2024
@coratgerl
Copy link
Contributor Author

@Jarred-Sumner This issue is problematic for my use case, can you review this one if you have the time ? 🙏

Thanks for all the work done !

@lanezhao
Copy link

lanezhao commented Jul 30, 2024

I have the same issue. Please please fix it. It's a basically need to be when create http server. @Jarred-Sumner

const port = 4444;

bun.serve({
  port,
  fetch() {
    return new Response('', {
      statusText: 'customStatusText',
    });
  },
});

const host = `http://localhost:${port}`;

await fetch(`${host}`)
  .then((res) => {
    console.debug({ res, statusText: res.statusText });
  });

@lanezhao
Copy link

lanezhao commented Sep 8, 2024

2024-09-07 10 22 47

@Jarred-Sumner I think this code change has not been merged correctly. Problems have persisted in the last few versions. I need to use "custom statusText" in bun.js, for my open source framework. Please fix it.

@lanezhao
Copy link

Can sameone respond? This is a major issue when creating web servers with Bun.js. I think it's not so difficult to fix. @Jarred-Sumner @dylan-conway @coratgerl Please!!!

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.

2 participants