From ece512c631d6c130b6db58acdfb324a700329e26 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Fri, 20 Apr 2018 17:11:32 -0700 Subject: [PATCH] Rename PrefixedRedirect to FlushingHandler & comment It's not clear whether this code is necessary, but investigating this was outside of the scope of this PR. --- server/mux.go | 4 ++-- server/prefixing_redirector.go | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/server/mux.go b/server/mux.go index 6f74153850..cecf7a99b6 100644 --- a/server/mux.go +++ b/server/mux.go @@ -321,9 +321,9 @@ func NewMux(opts MuxOpts, service Service) http.Handler { // Create middleware that redirects to the appropriate provider logout router.GET("/oauth/logout", Logout("/", opts.Basepath, allRoutes.AuthRoutes)) - out = Logger(opts.Logger, PrefixedRedirect(auth)) + out = Logger(opts.Logger, FlushingHandler(auth)) } else { - out = Logger(opts.Logger, PrefixedRedirect(router)) + out = Logger(opts.Logger, FlushingHandler(router)) } return out diff --git a/server/prefixing_redirector.go b/server/prefixing_redirector.go index 30884cdcfb..0317ceb399 100644 --- a/server/prefixing_redirector.go +++ b/server/prefixing_redirector.go @@ -4,28 +4,29 @@ import ( "net/http" ) -type interceptingResponseWriter struct { +type flushingResponseWriter struct { http.ResponseWriter } -func (i *interceptingResponseWriter) WriteHeader(status int) { - i.ResponseWriter.WriteHeader(status) +func (f *flushingResponseWriter) WriteHeader(status int) { + f.ResponseWriter.WriteHeader(status) } // Flush is here because the underlying HTTP chunked transfer response writer // to implement http.Flusher. Without it data is silently buffered. This // was discovered when proxying kapacitor chunked logs. -func (i *interceptingResponseWriter) Flush() { - if flusher, ok := i.ResponseWriter.(http.Flusher); ok { +func (f *flushingResponseWriter) Flush() { + if flusher, ok := f.ResponseWriter.(http.Flusher); ok { flusher.Flush() } } -// PrefixedRedirect alters the Location header of downstream http.Handlers -// to include a specified prefix -func PrefixedRedirect(next http.Handler) http.Handler { +// FlushingHandler may not actually do anything, but it was ostensibly +// implemented to flush response writers that can be flushed for the +// purposes in the comment above. +func FlushingHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - iw := &interceptingResponseWriter{ + iw := &flushingResponseWriter{ ResponseWriter: w, } next.ServeHTTP(iw, r)