-
Notifications
You must be signed in to change notification settings - Fork 18
/
stat_handler_wrapper.go
116 lines (109 loc) · 2.53 KB
/
stat_handler_wrapper.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//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)
pusher, canPush := w.(http.Pusher)
//nolint:staticcheck
closeNotifier, canNotify := w.(http.CloseNotifier)
if canFlush && canHijack && canPush && canNotify {
return struct {
http.ResponseWriter
http.Flusher
http.Hijacker
http.Pusher
http.CloseNotifier
}{rw, flusher, hijacker, pusher, closeNotifier}
} else if canFlush && canHijack && canPush {
return struct {
http.ResponseWriter
http.Flusher
http.Hijacker
http.Pusher
}{rw, flusher, hijacker, pusher}
} else if canFlush && canHijack && canNotify {
return struct {
http.ResponseWriter
http.Flusher
http.Hijacker
http.CloseNotifier
}{rw, flusher, hijacker, closeNotifier}
} else if canFlush && canPush && canNotify {
return struct {
http.ResponseWriter
http.Flusher
http.Pusher
http.CloseNotifier
}{rw, flusher, pusher, closeNotifier}
} else if canHijack && canPush && canNotify {
return struct {
http.ResponseWriter
http.Hijacker
http.Pusher
http.CloseNotifier
}{rw, hijacker, pusher, closeNotifier}
} else if canFlush && canHijack {
return struct {
http.ResponseWriter
http.Flusher
http.Hijacker
}{rw, flusher, hijacker}
} else if canFlush && canPush {
return struct {
http.ResponseWriter
http.Flusher
http.Pusher
}{rw, flusher, pusher}
} else if canFlush && canNotify {
return struct {
http.ResponseWriter
http.Flusher
http.CloseNotifier
}{rw, flusher, closeNotifier}
} else if canHijack && canPush {
return struct {
http.ResponseWriter
http.Hijacker
http.Pusher
}{rw, hijacker, pusher}
} else if canHijack && canNotify {
return struct {
http.ResponseWriter
http.Hijacker
http.CloseNotifier
}{rw, hijacker, closeNotifier}
} else if canPush && canNotify {
return struct {
http.ResponseWriter
http.Pusher
http.CloseNotifier
}{rw, pusher, 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 canPush {
return struct {
http.ResponseWriter
http.Pusher
}{rw, pusher}
} else if canNotify {
return struct {
http.ResponseWriter
http.CloseNotifier
}{rw, closeNotifier}
}
return rw
}