Skip to content

Add generic server-sent events support to Azure Core - #50146

Closed
Xiaofei Cao (XiaofeiCao) wants to merge 6 commits into
Azure:mainfrom
XiaofeiCao:xiaofeicao-draft-sse-core-support
Closed

Add generic server-sent events support to Azure Core#50146
Xiaofei Cao (XiaofeiCao) wants to merge 6 commits into
Azure:mainfrom
XiaofeiCao:xiaofeicao-draft-sse-core-support

Conversation

@XiaofeiCao

Copy link
Copy Markdown
Contributor

Summary

Adds minimal, single-response server-sent events support to azure-core, based on #50081.

  • Adds ServerSentEvent<T>, ServerSentEventListener<T>, and ServerSentEventStreams for synchronous listener and asynchronous Flux consumption.
  • Incrementally parses text/event-stream responses and supports optional service-defined terminal-event predicates.
  • Preserves live response bodies through REST proxy decoding and returns a closeable Response<BinaryData> implementation for streaming responses.
  • Prevents HttpLoggingPolicy from buffering SSE response bodies.
  • Closes the physical response on completion, failure, interruption, terminal events, or Reactor cancellation.
  • Bounds incomplete events to 16 MiB and uses a single data buffer to prevent unbounded heap growth.

Scope

This PR intentionally handles one established HTTP response. It does not reconnect, replay requests, or send Last-Event-Id. Search client APIs, generated models, and emitter work remain separate.

Contract

Response overloads require a closeable HTTP 200 or 204 response. Non-204 responses require exactly one text/event-stream content type and reject an explicit non-UTF-8 charset. Existing overloads complete on EOF or HTTP 204; predicate overloads require and inclusively deliver a matching terminal event.

Validation

  • Full azure-core test suite: 11,881 tests, 0 failures, 3 skipped
  • Checkstyle: 0 violations
  • SpotBugs: 0 findings

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ff0a367c-664e-4de0-902b-ddaae2c86546
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ff0a367c-664e-4de0-902b-ddaae2c86546
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: daa3657a-91d5-48fa-b7ae-6983091cab6a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: daa3657a-91d5-48fa-b7ae-6983091cab6a
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: daa3657a-91d5-48fa-b7ae-6983091cab6a
Bound incomplete server-sent events to 16 MiB and retain multi-line data in a single buffer to prevent unbounded heap growth.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the Azure.Core azure-core label Aug 14, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
34 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure.Core azure-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant