Skip to content

Support unbuffered streaming responses (SSE/Server-Sent Events) #315

@cfsbhawkins

Description

@cfsbhawkins

Problem to Solve

Problem

Relic doesn't support unbuffered streaming responses, making Server-Sent Events (SSE) impossible.

Expected Behavior

When using Body.fromDataStream() with an open-ended stream, data should be sent to the client as it's added to the stream, not buffered until the stream closes.

Current Behavior

Data added to the stream is buffered and never sent to the client. The client receives headers (200 OK, transfer-encoding: chunked) but 0 bytes of body data, even though the server code is adding data to the stream.

Proposal

Context

Shelf supports this via the context parameter with 'shelf.io.buffer_output': false:

return Response.ok(
  controller.stream.transform(utf8.encoder),
  context: {'shelf.io.buffer_output': false},
);

Use Case

Relic needs an equivalent mechanism to disable output buffering for SSE and long-polling use cases.

Alternatives

Web Sockets but that's a lot of overhead for just server side status updates.

Additional context

No response

How experienced are you with this library?

Beginner - Just getting started with this library

Are you interested in working on a PR for this?

  • I want to work on this

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Inbox 📫

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions