Merge pull request #77222 from liggitt/drop-proxy-workaround

Remove proxy workaround fixed in go 1.12.4
This commit is contained in:
Kubernetes Prow Robot 2019-04-30 14:11:24 -07:00 committed by GitHub
commit 2caf436db4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.