Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Sent Events #88

Closed
mtiller opened this issue Jan 8, 2023 · 5 comments
Closed

Server Sent Events #88

mtiller opened this issue Jan 8, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@mtiller
Copy link
Contributor

mtiller commented Jan 8, 2023

I was looking for a way for huma resources to implement Server Sent Events. In that example, they see if the response writer conforms to the Flusher interface. If it does, there is no problem. But I've tried that with huma.Context and it does not conform to the Flusher interface. As a result, it isn't possible to flush the events as they are generated.

Any suggestions here?

@mtiller
Copy link
Contributor Author

mtiller commented Jan 8, 2023

A related question would be how to integrate websockets, should the need arise?

@danielgtaylor
Copy link
Owner

@mtiller this is something I've been meaning to look into as we may start using SSE in the next few months as well. I don't know whether it is currently possible (it seems like it's not) so maybe we need to add Flusher to the huma.Context interface as a first step.

@danielgtaylor danielgtaylor added the enhancement New feature or request label Jan 9, 2023
@mt35-rs
Copy link
Contributor

mt35-rs commented Jan 9, 2023

What I don't quite get is why the ResponseWriter doesn't already implement the Flusher interface. I'm pretty sure I read that http.ResponseWriter does but it is possible that it could be wrapped by something that doesn't. But I didn't see any case where huma was wrapping it. Just ensuring that the ResponseWriter that is used to compose huma.Context supports Flusher would be sufficient presumably. I wonder if simply nesting the ResponseWriter is somehow interfering with the ability to cast it to Flusher?

@mt35-rs
Copy link
Contributor

mt35-rs commented Jan 10, 2023

I've added a pull request (#89) that resolves this. If you could merge this, my tests indicate that SSE should work at that point.

@danielgtaylor
Copy link
Owner

Closing as this was resolved in #89 for Huma v1, and Huma v2 has an sse package to enable this functionality at a higher level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants