2017-05-05 22:17:35 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
type interceptingResponseWriter struct {
|
|
|
|
http.ResponseWriter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *interceptingResponseWriter) WriteHeader(status int) {
|
|
|
|
i.ResponseWriter.WriteHeader(status)
|
|
|
|
}
|
|
|
|
|
2017-10-26 22:38:20 +00:00
|
|
|
// 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() {
|
2018-04-20 23:52:48 +00:00
|
|
|
if flusher, ok := i.ResponseWriter.(http.Flusher); ok {
|
|
|
|
flusher.Flush()
|
2017-10-26 22:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PrefixedRedirect alters the Location header of downstream http.Handlers
|
2017-05-05 22:17:35 +00:00
|
|
|
// to include a specified prefix
|
2018-04-20 23:48:50 +00:00
|
|
|
func PrefixedRedirect(next http.Handler) http.Handler {
|
2017-05-05 22:17:35 +00:00
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
2017-10-26 22:38:20 +00:00
|
|
|
iw := &interceptingResponseWriter{
|
|
|
|
ResponseWriter: w,
|
|
|
|
}
|
2017-05-05 22:17:35 +00:00
|
|
|
next.ServeHTTP(iw, r)
|
|
|
|
})
|
|
|
|
}
|