Sending 204 when event/stream is done? #5130
-
I'm using Flask to send server-sent events: https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events-intro I'm using a Response() with a generator function and event/stream mime-type: The issue is that I want to be able to tell the client that the stream is done (generator is exhausted), and the spec says that sending a 204 will signal that. I don't see an obvious way to send a 204 using this way of using Response, however. Is that possible? (My workaround is to send a "bye-bye-bye" event and have the client listen for that, but it'd be cleaner for the client to not have to do the closing.) Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
usually you can just ignore it. if you don't plan to make things stateful by letting a client specify the last event they got (last-event-id header) and then resending anything they missed since they disconnected it won't make sense to implement any other reconnect-related logic either. depends on your usecase of course... |
Beta Was this translation helpful? Give feedback.
-
As per the spec, the 204 is to be used after the client reconnects The expectation is that the client keeps reconnecting, and the server can use a204 on the next connection |
Beta Was this translation helpful? Give feedback.
-
Ahh, right, of course, that makes sense. Thanks all! |
Beta Was this translation helpful? Give feedback.
As per the spec, the 204 is to be used after the client reconnects
The expectation is that the client keeps reconnecting, and the server can use a204 on the next connection