-
Notifications
You must be signed in to change notification settings - Fork 18
/
stat_handler_wrapper_1.7.go
61 lines (55 loc) · 1.25 KB
/
stat_handler_wrapper_1.7.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build !go1.8
// +build !go1.8
package stats
import "net/http"
func (h *httpHandler) wrapResponse(w http.ResponseWriter) http.ResponseWriter {
rw := &responseWriter{
ResponseWriter: w,
handler: h,
}
flusher, canFlush := w.(http.Flusher)
hijacker, canHijack := w.(http.Hijacker)
closeNotifier, canNotify := w.(http.CloseNotifier)
if canFlush && canHijack && canNotify {
return struct {
http.ResponseWriter
http.Flusher
http.Hijacker
http.CloseNotifier
}{rw, flusher, hijacker, closeNotifier}
} else if canFlush && canHijack {
return struct {
http.ResponseWriter
http.Flusher
http.Hijacker
}{rw, flusher, hijacker}
} else if canFlush && canNotify {
return struct {
http.ResponseWriter
http.Flusher
http.CloseNotifier
}{rw, flusher, closeNotifier}
} else if canHijack && canNotify {
return struct {
http.ResponseWriter
http.Hijacker
http.CloseNotifier
}{rw, hijacker, closeNotifier}
} else if canFlush {
return struct {
http.ResponseWriter
http.Flusher
}{rw, flusher}
} else if canHijack {
return struct {
http.ResponseWriter
http.Hijacker
}{rw, hijacker}
} else if canNotify {
return struct {
http.ResponseWriter
http.CloseNotifier
}{rw, closeNotifier}
}
return rw
}