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

Returns JSON instead of text/event-stream #920

Open
HK-SHAO opened this issue Nov 19, 2024 · 1 comment
Open

Returns JSON instead of text/event-stream #920

HK-SHAO opened this issue Nov 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@HK-SHAO
Copy link

HK-SHAO commented Nov 19, 2024

What version of Elysia is running?

1.1.25

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

set.headers['Content-Type'] = 'application/json';
return stream satisfies Promise<ReadableStream<string>>;

What is the expected behavior?

Received a response with:

Content-Type: application/json; charset=utf-8

What do you see instead?

Received a response with:

Content-Type: application/json, text/event-stream; charset=utf-8

Additional information

In the response body, I wish I could stream a string.
The string is actually a JSON text (generated by my streaming stringify)

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@HK-SHAO HK-SHAO added the bug Something isn't working label Nov 19, 2024
@HK-SHAO HK-SHAO changed the title Returns JSON instead of text/event-stream. Returns JSON instead of text/event-stream Nov 19, 2024
@SaltyAom
Copy link
Member

SaltyAom commented Dec 4, 2024

I would like to hear what scenario led you to return application/json with event stream data.

However, you can use mapResponse to override Elysia default response like this:

new Elysia()
	.get('/', () => {}, {
		mapResponse({ response }) {
			if (response instanceof ReadableStream)
				return new Response(response, {
					headers: {
						'Content-Type': 'application/octet-stream'
					}
				})
		}
	})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants