Skip to content

Conversation

@joroshiba
Copy link

@joroshiba joroshiba commented Sep 30, 2025

This adds support for SSE streaming on REST Protocol via an option, but is not enabled by default. When using WithRESTServerSentEvents(), only streaming rpcs using REST protocol when request header Accept is set to text/event-stream are affected.

When SSE is being used:

  • on connect an event open is fired
  • rpc streamed responses written with a data containing the JSON serialized protobuf response object in the data field of the event.
  • error events are generated when error encountered
  • when the stream is closed the complete event is fired

There are SSE specific field configurations available for event id and retry. To support these fields, custom directives are parsed out of the google.api.http response_body annotation field, to configure these fields to be set as specifed for each data sent.

  • SSE_EVENT=<field_name> will change the event name on the SSE to be derived from the field specified
  • SSE_ID=<field_name>, will change the event id to be derived from the field specified. If this is not set no ID is specified, when it is the id field will be blank unless the attribute has a value on the rendered data.
  • SSE_RETRY=<field_name>, will set the retry field based on the value, assuming it is all ascii numbers.
  • SSE_OMIT will, if any of the above are set, omit the fields specified from the data json body.

Related issue:
#161

Signed-off-by: Jordan Oroshiba <[email protected]>
@joroshiba joroshiba marked this pull request as ready for review September 30, 2025 22:14
…support via protobuf annotation directives

Signed-off-by: Jordan Oroshiba <[email protected]>
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.

1 participant