Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

goproxy buffers SSE (content-type: text/event-stream) #5

Open
ChristianSchenk711 opened this issue Feb 7, 2020 · 0 comments
Open

Comments

@ChristianSchenk711
Copy link

When using goproxy with SSE, the events are buffered, rendering that useless.

Scenario:

Problem: the goproxy will always return 80 messages as a bunch and buffer inbetween. That renders SSE unusable through goproxy, because the point of SSE is to informed about each individual message.

I would suggest to handle SSE with an explicit Flush, e.g. like that in proxy.go (line 150):

	var copyWriter io.Writer = w
	if w.Header().Get("content-type") == "text/event-stream" {
		copyWriter = NewFlushWriter(w)
	}
	nr, err := io.Copy(copyWriter , resp.Body)

The FlushWriter would just overwrite "write" and call a flush afterwards:


type FlushWriter struct {
	w      io.Writer
}

func NewFlushWriter(w io.Writer) *FlushWriter {
	return &FlushWriter{w: w}
}

func (w *FlushWriter) Write(b []byte) (int, error) {
	bytes, err := w.w.Write(b)
	if f, ok := w.w.(http.Flusher); ok {
		f.Flush()
	} 
	return bytes, err
}

I had initially reported that fix at eclipse-che/che#15942 but then realized that this is actually in goproxy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant