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

Render: SSE limited to data field #1700

knodesec opened this issue Jun 19, 2019 · 0 comments


Copy link

commented Jun 19, 2019

The current implementation of SSE in encodes a "type" and "data" into a JSON object, and sends the string over the SSE connection in the format data: <json_object>. This limits the use of other fields such as event, id, retry.

Current SSE implementations would probably rely on parsing the JSON from a clientside evtSource.onmessage and won't be able to utilize an evtSource.addEventListerner for different events generated by the backend, and won't be able to set the "retry" or "id" fields that the browsers use.

Are we interested in changing the implementation of SSE in render to allow more use of this feature? Without breaking existing applications, we would still have to rely on encoding into JSON with a redundant "type" field.

Something like this would allow a WriteWithEvent method to write the event and any normal data through the same Write method, which will also call the es.Flush() and similar things could be written for retry and id.

func (es *EventSource) WriteWithEvent(e, t string, d interface{}) error {
	_, err := es.w.Write([]byte(fmt.Sprintf("event: %s\n", e)))
	if err != nil {
		return err
	err = es.Write(t, d)
	if err != nil {
		return err
	return nil

Please note I'm not really a developer and this might appear to be a horrible solution.

@stanislas-m stanislas-m added the proposal label Jul 5, 2019

@stanislas-m stanislas-m added this to the Proposal milestone Jul 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.