okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Expose SSE retry time updates via the public API

Open jamesmissen opened this issue 1 year ago • 4 comments

Issue #5471 was closed with the recommendation to reconnect to SSE streams in the application layer.

It would be helpful to expose the retry times in retry fields from the event stream, so that any reconnection attempts in a higher layer could respect the latest retry time if desired.

Currently, the retry times are parsed but they remain in the internal API only, terminating here:

https://github.com/square/okhttp/blob/75b9c267744cdd2e8b222d247052748ff0954304/okhttp-sse/src/main/kotlin/okhttp3/sse/internal/RealEventSource.kt#L127-L129

jamesmissen avatar Jan 18 '24 05:01 jamesmissen

Yep, this seems like a valid part of the API. Exposed in other frameworks like https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/codec/ServerSentEvent.java

And as you say, web EventSource implements retry observing that. https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation

@swankjesse @JakeWharton any objection to exposing? It would allow building a correct retrying implementation on top.

yschimke avatar Jan 19 '24 21:01 yschimke

Let's expose. We don't support automatic retry so we need to surface this to the caller.

JakeWharton avatar Jan 22 '24 21:01 JakeWharton