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

Add space between SSE field and value for compatibility #2149

Merged
merged 2 commits into from
Sep 16, 2023

Conversation

ttys3
Copy link
Contributor

@ttys3 ttys3 commented Aug 4, 2023

according to https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation using field: value style is OK.

Collect the characters on the line after the first U+003A COLON character (:), and let value be that string. If value starts with a U+0020 SPACE character, remove it from value.

Motivation

other client side tools may detect the data field rely on the space,

like this one https://github.com/openai/openai-python/blob/b82a3f7e4c462a8a10fa445193301a3cefef9a4a/openai/api_requestor.py#L106

and this one: https://github.com/sashabaranov/go-openai/blob/71a24931dbc5b7029901ff963dc4d0d2509aa7ed/stream_reader.go#L14

in this case, axum powered http server responsed sse event will not be correctly parsed by theses libs,
and they can not receive any message from axum powered sse server.

Solution

add a U+0020 SPACE character, between field and value

Related

openai/openai-python#559

openai/openai-python#502

#2146

@ttys3 ttys3 changed the title chore(sse): add space between event name and value for compatibility chore(sse): add space between field and value for compatibility Aug 4, 2023
according to https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation
using `field: value` style is OK.

> Collect the characters on the line after the first U+003A COLON character (:), and let value be that string. If value starts with a U+0020 SPACE character, remove it from value.

other client side tools may detect the `data` field rely on the space,

like this one https://github.com/openai/openai-python/blob/b82a3f7e4c462a8a10fa445193301a3cefef9a4a/openai/api_requestor.py#L106

and this one: https://github.com/sashabaranov/go-openai/blob/71a24931dbc5b7029901ff963dc4d0d2509aa7ed/stream_reader.go#L14
@davidpdrsn davidpdrsn changed the title chore(sse): add space between field and value for compatibility Add space between SSE field and value for compatibility Sep 16, 2023
Copy link
Member

@davidpdrsn davidpdrsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@davidpdrsn davidpdrsn enabled auto-merge (squash) September 16, 2023 19:36
@davidpdrsn davidpdrsn merged commit 268ba08 into tokio-rs:main Sep 16, 2023
18 checks passed
davidpdrsn added a commit that referenced this pull request Sep 16, 2023
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
davidpdrsn added a commit that referenced this pull request Sep 16, 2023
Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
@michaelfeil
Copy link

Thanks @ttys3

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.

None yet

3 participants