Add WebAPIResponseEventStream for API streaming results.

Review Request #13281 — Created Sept. 21, 2023 and submitted — Latest diff uploaded

Information

Djblets
release-4.x

Reviewers

This builds upon the new EventStreamHttpResponse class to easily
enable APIs to stream events and results to callers using Server-Sent
Events.

WebAPIResource handlers can now return a generator or generator
function that yields messages for the event stream. These will be
serialized one-by-one using the same API response serialization logic we
otherwise use for the API. Callers can parse those as they come in,
utilizing a X-Event-Data-Mimetype header to know the resource type for
any "message" events (the default when event isn't specified) to
intelligently handle parsing.

This can be used for HTTP GET/POST/PUT requests, making it possible to
stream progress notification or build a message bus using the API.

Unit tests pass.

Tested this with an EventSource in JavaScript, verifying that events
were properly coming in and could be parsed correctly.

Commits

Files