forked from influxdata/chronograf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefixing_redirector.go
34 lines (29 loc) · 924 Bytes
/
prefixing_redirector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package server
import (
"net/http"
)
type flushingResponseWriter struct {
http.ResponseWriter
}
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 (f *flushingResponseWriter) Flush() {
if flusher, ok := f.ResponseWriter.(http.Flusher); ok {
flusher.Flush()
}
}
// 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 := &flushingResponseWriter{
ResponseWriter: w,
}
next.ServeHTTP(iw, r)
})
}