MCPcopy Index your code
hub / github.com/felixge/httpsnoop / Wrap

Function Wrap

wrap_generated.go:107–1207  ·  view source on GitHub ↗

Wrap returns a wrapped version of w that provides the exact same interface as w. Specifically if w implements any combination of: - http.Flusher - httpFlushError - http.CloseNotifier - http.Hijacker - io.ReaderFrom - deadliner - fullDuplexEnabler - http.Pusher - io.StringWriter The wrapped version

(w http.ResponseWriter, hooks Hooks)

Source from the content-addressed store, hash-verified

105// The CaptureMetrics implementation serves as a working example for how the
106// hooks can be used.
107func Wrap(w http.ResponseWriter, hooks Hooks) http.ResponseWriter {
108 state := &rwState{w: w}
109 var combo uint16
110 if hooks.Header != nil {
111 state.header = hooks.Header(w.Header)
112 }
113 if hooks.WriteHeader != nil {
114 state.writeHeader = hooks.WriteHeader(w.WriteHeader)
115 }
116 if hooks.Write != nil {
117 state.write = hooks.Write(w.Write)
118 }
119 if t0, i0 := w.(http.Flusher); i0 {
120 combo |= 1 << 8
121 if hooks.Flush != nil {
122 state.flush = hooks.Flush(t0.Flush)
123 }
124 }
125 if t1, i1 := w.(httpFlushError); i1 {
126 combo |= 1 << 7
127 if hooks.FlushError != nil {
128 state.flushError = hooks.FlushError(t1.FlushError)
129 } else if state.flush != nil {
130 state.flushError = func() (err error) { hooks.Flush(func() { err = t1.FlushError() })(); return err }
131 }
132 }
133 if t2, i2 := w.(http.CloseNotifier); i2 {
134 combo |= 1 << 6
135 if hooks.CloseNotify != nil {
136 state.closeNotify = hooks.CloseNotify(t2.CloseNotify)
137 }
138 }
139 if t3, i3 := w.(http.Hijacker); i3 {
140 combo |= 1 << 5
141 if hooks.Hijack != nil {
142 state.hijack = hooks.Hijack(t3.Hijack)
143 }
144 }
145 if t4, i4 := w.(io.ReaderFrom); i4 {
146 combo |= 1 << 4
147 if hooks.ReadFrom != nil {
148 state.readFrom = hooks.ReadFrom(t4.ReadFrom)
149 }
150 }
151 if t5, i5 := w.(deadliner); i5 {
152 combo |= 1 << 3
153 if hooks.SetReadDeadline != nil {
154 state.setReadDeadline = hooks.SetReadDeadline(t5.SetReadDeadline)
155 }
156 if hooks.SetWriteDeadline != nil {
157 state.setWriteDeadline = hooks.SetWriteDeadline(t5.SetWriteDeadline)
158 }
159 }
160 if t6, i6 := w.(fullDuplexEnabler); i6 {
161 combo |= 1 << 2
162 if hooks.EnableFullDuplex != nil {
163 state.enableFullDuplex = hooks.EnableFullDuplex(t6.EnableFullDuplex)
164 }

Callers 10

TestUnwrapFunction · 0.85
TestUnwrapMultipleLayersFunction · 0.85
CaptureMetricsMethod · 0.85
TestWrapFunction · 0.85
BenchmarkWrapFunction · 0.85
TestWrap_integrationFunction · 0.85

Calls 13

FlushErrorMethod · 0.65
SetReadDeadlineMethod · 0.65
SetWriteDeadlineMethod · 0.65
EnableFullDuplexMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
WriteMethod · 0.45
FlushMethod · 0.45
CloseNotifyMethod · 0.45
HijackMethod · 0.45
ReadFromMethod · 0.45
PushMethod · 0.45

Tested by 9

TestUnwrapFunction · 0.68
TestUnwrapMultipleLayersFunction · 0.68
TestWrapFunction · 0.68
BenchmarkWrapFunction · 0.68
TestWrap_integrationFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…