You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a streaming (text/event-stream) example and I noticed the generated code doesn't flush the output properly. I've tracked this down to the code in pkg/codegen/templates/strict/strict-interface.tmpl, which looks something like this:
ifcloser, ok:=response.Body.(io.ReadCloser); ok {
defercloser.Close()
}
_, err:=io.Copy(w, response.Body)
returnerr
io.Copy will buffer the response, which would be fine for most cases, but would add an arbitrary delay on text/event-stream, which is pretty bad as the delay can easy be 10+ seconds. text/event-streams are often time-sensitive.
What we wanna do in here is to check the content-type and if it is text/event-stream, we wanna flush after each write. similar code is in the httputil/reverseproxy part of the stdlib in case anyone wants to see other places where text/event-stream is a special case.
Since fixing this would touch the generated code I thought I'd at least bring the topic up before trying to fix this myself. Let me know how I should proceed.
The text was updated successfully, but these errors were encountered:
Hi.
I'm working on a streaming (text/event-stream) example and I noticed the generated code doesn't flush the output properly. I've tracked this down to the code in pkg/codegen/templates/strict/strict-interface.tmpl, which looks something like this:
io.Copy will buffer the response, which would be fine for most cases, but would add an arbitrary delay on text/event-stream, which is pretty bad as the delay can easy be 10+ seconds. text/event-streams are often time-sensitive.
What we wanna do in here is to check the content-type and if it is text/event-stream, we wanna flush after each write. similar code is in the httputil/reverseproxy part of the stdlib in case anyone wants to see other places where text/event-stream is a special case.
Since fixing this would touch the generated code I thought I'd at least bring the topic up before trying to fix this myself. Let me know how I should proceed.
The text was updated successfully, but these errors were encountered: