mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #77222 from liggitt/drop-proxy-workaround
Remove proxy workaround fixed in go 1.12.4
This commit is contained in:
commit
2caf436db4
@ -230,34 +230,7 @@ func (h *UpgradeAwareHandler) ServeHTTP(w http.ResponseWriter, req *http.Request
|
||||
proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: h.Location.Scheme, Host: h.Location.Host})
|
||||
proxy.Transport = h.Transport
|
||||
proxy.FlushInterval = h.FlushInterval
|
||||
proxy.ServeHTTP(maybeWrapFlushHeadersWriter(w), newReq)
|
||||
}
|
||||
|
||||
// maybeWrapFlushHeadersWriter wraps the given writer to force flushing headers prior to writing the response body.
|
||||
// if the given writer does not support http.Flusher, http.Hijacker, and http.CloseNotifier, the original writer is returned.
|
||||
// TODO(liggitt): drop this once https://github.com/golang/go/issues/31125 is fixed
|
||||
func maybeWrapFlushHeadersWriter(w http.ResponseWriter) http.ResponseWriter {
|
||||
flusher, isFlusher := w.(http.Flusher)
|
||||
hijacker, isHijacker := w.(http.Hijacker)
|
||||
closeNotifier, isCloseNotifier := w.(http.CloseNotifier)
|
||||
// flusher, hijacker, and closeNotifier are all used by the ReverseProxy implementation.
|
||||
// if the given writer can't support all three, return the original writer.
|
||||
if !isFlusher || !isHijacker || !isCloseNotifier {
|
||||
return w
|
||||
}
|
||||
return &flushHeadersWriter{w, flusher, hijacker, closeNotifier}
|
||||
}
|
||||
|
||||
type flushHeadersWriter struct {
|
||||
http.ResponseWriter
|
||||
http.Flusher
|
||||
http.Hijacker
|
||||
http.CloseNotifier
|
||||
}
|
||||
|
||||
func (w *flushHeadersWriter) WriteHeader(code int) {
|
||||
w.ResponseWriter.WriteHeader(code)
|
||||
w.Flusher.Flush()
|
||||
proxy.ServeHTTP(w, newReq)
|
||||
}
|
||||
|
||||
// tryUpgrade returns true if the request was handled.
|
||||
|
Loading…
Reference in New Issue
Block a user