Closed
Description
The Proxy middleware currently doesn't support Server-Sent Events. A HTTP request expecting a text/event-stream
response is discarded because of this line in proxy.go
. I guess it may be an expected behavior, however adding support for SSE would be very nice.
To solve this, we could use a httputil.ReverseProxy
with a FlushInterval
of ~100ms. We could add a new proxyHTTP factory like so :
func proxyHTTPWithFlushInterval(t *ProxyTarget, interval time.Duration) http.Handler {
proxy := httputil.NewSingleHostReverseProxy(t.URL)
proxy.FlushInterval = interval
return proxy
}
Then use it in the switch statement
case req.Header.Get(echo.HeaderAccept) == "text/event-stream":
proxyHTTPWithFlushInterval(tgt, 100*time.Millisecond).ServeHTTP(res, req)
This may introduce performance issues but since it's reserved for specific use cases, it shouldn't be a problem.
Btw, Echo is an awesome framework, loving it !