From eba044a005db22ece1315b5533972c5dd88a0607 Mon Sep 17 00:00:00 2001 From: hwzhu-hoop <18306137521@163.com> Date: Fri, 12 Sep 2025 07:40:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?sidecar=E6=A8=A1=E5=BC=8F=E6=94=AF=E6=8C=81?= =?UTF-8?q?sse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/protocol/http/sidecar.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/proxy/protocol/http/sidecar.go b/proxy/protocol/http/sidecar.go index d782657..8faed87 100755 --- a/proxy/protocol/http/sidecar.go +++ b/proxy/protocol/http/sidecar.go @@ -215,6 +215,33 @@ func RemoteRequestHandler(w http.ResponseWriter, r *http.Request) { } } +func copySSEChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) { + defer func() { + if err := resp.Body.Close(); err != null { + openlog.Error("Http sse response close error: " + err.Error()) + } + }() + + reader := bufio.NewReader(resp.Body) + for { + line, err := reader.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + openlog.Error("Error reading response line: " + err.Error()) + return + } + + if _, err = w.Write([]byte(line)); err != nil { + openlog.Error("Error reading response line: " + err.Error()) + return + } + + w.(http.Flusher).Flush() + } +} + func copyChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) { if resp == nil { openlog.Warn("response is nil because of unknown reason") From d265324cf24421c71f64f7e38928bc4762f4a40b Mon Sep 17 00:00:00 2001 From: hwzhu-hoop <18306137521@163.com> Date: Fri, 12 Sep 2025 07:59:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?sidecar=E6=A8=A1=E5=BC=8F=E6=94=AF=E6=8C=81?= =?UTF-8?q?sse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/protocol/http/sidecar.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/proxy/protocol/http/sidecar.go b/proxy/protocol/http/sidecar.go index 8faed87..2851f8c 100755 --- a/proxy/protocol/http/sidecar.go +++ b/proxy/protocol/http/sidecar.go @@ -18,6 +18,7 @@ package http import ( + "bufio" "context" "encoding/json" "errors" @@ -54,6 +55,8 @@ var sr = resolver.GetSourceResolver() const ( XForwardedPort = "X-Forwarded-Port" XForwardedHost = "X-Forwarded-Host" + SSEHeaderKey = "Content-Type" + SSEHeaderValue = "text/event-stream" ) var ( @@ -251,6 +254,11 @@ func copyChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) { copyHeader(w.Header(), resp.Header) w.WriteHeader(resp.StatusCode) + if isSSEResponse(resp.Header) { + copySSEChassisResp2HttpResp(w, resp) + return + } + _, err := io.Copy(w, resp.Body) if err != nil { openlog.Error("can not copy: " + err.Error()) @@ -355,7 +363,11 @@ func prepareRequest(req *http.Request) { func copyHeader(dst, src http.Header) { for k, vs := range src { for _, v := range vs { - dst.Add(k, v) + if SSEHeaderKey == k && strings.Contains(v, SSEHeaderValue) { + dts.Add(SSEHeaderKey, SSEHeaderValue) + } else { + dst.Add(k, v) + } } } } @@ -363,3 +375,10 @@ func copyHeader(dst, src http.Header) { func postProcessResponse(rsp *http.Response) { rsp.Header.Del("Connection") } + +func isSSEResponse(header http.Header) bool { + if header == nil { + return false + } + return SSEHeaderValue == header.Get(SSEHeaderKey) +} From 9681b604d14fc2384b60ce54642aebe64677cdf1 Mon Sep 17 00:00:00 2001 From: hwzhu-hoop <64527269+hwzhu-hoop@users.noreply.github.com> Date: Wed, 28 Jan 2026 22:10:27 +0800 Subject: [PATCH 3/3] support sse --- proxy/protocol/http/sidecar.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/protocol/http/sidecar.go b/proxy/protocol/http/sidecar.go index 2851f8c..0666629 100755 --- a/proxy/protocol/http/sidecar.go +++ b/proxy/protocol/http/sidecar.go @@ -220,7 +220,7 @@ func RemoteRequestHandler(w http.ResponseWriter, r *http.Request) { func copySSEChassisResp2HttpResp(w http.ResponseWriter, resp *http.Response) { defer func() { - if err := resp.Body.Close(); err != null { + if err := resp.Body.Close(); err != nil { openlog.Error("Http sse response close error: " + err.Error()) } }() @@ -364,7 +364,7 @@ func copyHeader(dst, src http.Header) { for k, vs := range src { for _, v := range vs { if SSEHeaderKey == k && strings.Contains(v, SSEHeaderValue) { - dts.Add(SSEHeaderKey, SSEHeaderValue) + dst.Add(SSEHeaderKey, SSEHeaderValue) } else { dst.Add(k, v) }