Skip to content

Commit

Permalink
Feat: support hijacker for proxy resp writer
Browse files Browse the repository at this point in the history
Signed-off-by: Yin Da <[email protected]>
  • Loading branch information
Somefive authored and yue9944882 committed Mar 1, 2023
1 parent 3cdb7b3 commit 69d4f88
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/apis/cluster/v1alpha1/clustergateway_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ var (

type proxyResponseWriter struct {
http.ResponseWriter
http.Hijacker
http.Flusher
statusCode int
}

Expand All @@ -210,8 +212,15 @@ func (in *proxyResponseWriter) WriteHeader(statusCode int) {
in.ResponseWriter.WriteHeader(statusCode)
}

func newProxyResponseWriter(_writer http.ResponseWriter) *proxyResponseWriter {
writer := &proxyResponseWriter{ResponseWriter: _writer, statusCode: http.StatusOK}
writer.Hijacker, _ = _writer.(http.Hijacker)
writer.Flusher, _ = _writer.(http.Flusher)
return writer
}

func (p *proxyHandler) ServeHTTP(_writer http.ResponseWriter, request *http.Request) {
writer := &proxyResponseWriter{_writer, http.StatusOK}
writer := newProxyResponseWriter(_writer)
defer func() {
p.finishFunc(writer.statusCode)
}()
Expand Down

0 comments on commit 69d4f88

Please sign in to comment.