Reverse proxy, the stream works, but flush does not work

Content-Type:[text/event-stream],

The effect is the same as when re.flush is not used, and about 200 bytes are buffered before sending to the client, It seems to refresh every 3 seconds., The following is the code, How do I get it to refresh every 50ms?

for i := 0; i < 100; i++ {
io.Copy(mw, originServerResponse.Body)
err := rc.Flush()
if err != nil {
fmt.Println(err)
}
time.Sleep(50 * time.Millisecond)
}
.

Why don’t you try adding a buf layer? Put the data you need for 50ms into buf and send it all at once.

bs := new(bytes.Buffer) //Replace it with a size-limited buf !!!
	go func() {
		// do some ...
		_, _ = io.Copy(bs, originServerResponse.Body)
	}()
	tr := time.NewTicker(50 * time.Millisecond) //If you're using a timer, remember reset
	for {
		//If you have ctx, use select
		<-tr.C
		_, _ = io.Copy(rc, bs)
		rc.Flush()
	}