Codebase list golang-github-go-kit-kit / 121aeb2
feat(http): make interceptingWriter reimplement common interfaces from stdlib. (#1212) successor to #1093 and closes #1092. 谷溪 authored 2 years ago GitHub committed 2 years ago
3 changed file(s) with 1297 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
0 package http
1
2 import (
3 "io"
4 "net/http"
5 )
6
7 type interceptingWriter struct {
8 http.ResponseWriter
9 code int
10 written int64
11 }
12
13 // WriteHeader may not be explicitly called, so care must be taken to
14 // initialize w.code to its default value of http.StatusOK.
15 func (w *interceptingWriter) WriteHeader(code int) {
16 w.code = code
17 w.ResponseWriter.WriteHeader(code)
18 }
19
20 func (w *interceptingWriter) Write(p []byte) (int, error) {
21 n, err := w.ResponseWriter.Write(p)
22 w.written += int64(n)
23 return n, err
24 }
25
26 // reimplementInterfaces returns a wrapped version of the embedded ResponseWriter
27 // and selectively implements the same combination of additional interfaces as
28 // the wrapped one. The interfaces it may implement are: http.Hijacker,
29 // http.CloseNotifier, http.Pusher, http.Flusher and io.ReaderFrom. The standard
30 // library is known to assert the existence of these interfaces and behaves
31 // differently. This implementation is derived from
32 // https://github.com/felixge/httpsnoop.
33 func (w *interceptingWriter) reimplementInterfaces() http.ResponseWriter {
34 var (
35 hj, i0 = w.ResponseWriter.(http.Hijacker)
36 cn, i1 = w.ResponseWriter.(http.CloseNotifier)
37 pu, i2 = w.ResponseWriter.(http.Pusher)
38 fl, i3 = w.ResponseWriter.(http.Flusher)
39 rf, i4 = w.ResponseWriter.(io.ReaderFrom)
40 )
41
42 switch {
43 case !i0 && !i1 && !i2 && !i3 && !i4:
44 return struct {
45 http.ResponseWriter
46 }{w}
47 case !i0 && !i1 && !i2 && !i3 && i4:
48 return struct {
49 http.ResponseWriter
50 io.ReaderFrom
51 }{w, rf}
52 case !i0 && !i1 && !i2 && i3 && !i4:
53 return struct {
54 http.ResponseWriter
55 http.Flusher
56 }{w, fl}
57 case !i0 && !i1 && !i2 && i3 && i4:
58 return struct {
59 http.ResponseWriter
60 http.Flusher
61 io.ReaderFrom
62 }{w, fl, rf}
63 case !i0 && !i1 && i2 && !i3 && !i4:
64 return struct {
65 http.ResponseWriter
66 http.Pusher
67 }{w, pu}
68 case !i0 && !i1 && i2 && !i3 && i4:
69 return struct {
70 http.ResponseWriter
71 http.Pusher
72 io.ReaderFrom
73 }{w, pu, rf}
74 case !i0 && !i1 && i2 && i3 && !i4:
75 return struct {
76 http.ResponseWriter
77 http.Pusher
78 http.Flusher
79 }{w, pu, fl}
80 case !i0 && !i1 && i2 && i3 && i4:
81 return struct {
82 http.ResponseWriter
83 http.Pusher
84 http.Flusher
85 io.ReaderFrom
86 }{w, pu, fl, rf}
87 case !i0 && i1 && !i2 && !i3 && !i4:
88 return struct {
89 http.ResponseWriter
90 http.CloseNotifier
91 }{w, cn}
92 case !i0 && i1 && !i2 && !i3 && i4:
93 return struct {
94 http.ResponseWriter
95 http.CloseNotifier
96 io.ReaderFrom
97 }{w, cn, rf}
98 case !i0 && i1 && !i2 && i3 && !i4:
99 return struct {
100 http.ResponseWriter
101 http.CloseNotifier
102 http.Flusher
103 }{w, cn, fl}
104 case !i0 && i1 && !i2 && i3 && i4:
105 return struct {
106 http.ResponseWriter
107 http.CloseNotifier
108 http.Flusher
109 io.ReaderFrom
110 }{w, cn, fl, rf}
111 case !i0 && i1 && i2 && !i3 && !i4:
112 return struct {
113 http.ResponseWriter
114 http.CloseNotifier
115 http.Pusher
116 }{w, cn, pu}
117 case !i0 && i1 && i2 && !i3 && i4:
118 return struct {
119 http.ResponseWriter
120 http.CloseNotifier
121 http.Pusher
122 io.ReaderFrom
123 }{w, cn, pu, rf}
124 case !i0 && i1 && i2 && i3 && !i4:
125 return struct {
126 http.ResponseWriter
127 http.CloseNotifier
128 http.Pusher
129 http.Flusher
130 }{w, cn, pu, fl}
131 case !i0 && i1 && i2 && i3 && i4:
132 return struct {
133 http.ResponseWriter
134 http.CloseNotifier
135 http.Pusher
136 http.Flusher
137 io.ReaderFrom
138 }{w, cn, pu, fl, rf}
139 case i0 && !i1 && !i2 && !i3 && !i4:
140 return struct {
141 http.ResponseWriter
142 http.Hijacker
143 }{w, hj}
144 case i0 && !i1 && !i2 && !i3 && i4:
145 return struct {
146 http.ResponseWriter
147 http.Hijacker
148 io.ReaderFrom
149 }{w, hj, rf}
150 case i0 && !i1 && !i2 && i3 && !i4:
151 return struct {
152 http.ResponseWriter
153 http.Hijacker
154 http.Flusher
155 }{w, hj, fl}
156 case i0 && !i1 && !i2 && i3 && i4:
157 return struct {
158 http.ResponseWriter
159 http.Hijacker
160 http.Flusher
161 io.ReaderFrom
162 }{w, hj, fl, rf}
163 case i0 && !i1 && i2 && !i3 && !i4:
164 return struct {
165 http.ResponseWriter
166 http.Hijacker
167 http.Pusher
168 }{w, hj, pu}
169 case i0 && !i1 && i2 && !i3 && i4:
170 return struct {
171 http.ResponseWriter
172 http.Hijacker
173 http.Pusher
174 io.ReaderFrom
175 }{w, hj, pu, rf}
176 case i0 && !i1 && i2 && i3 && !i4:
177 return struct {
178 http.ResponseWriter
179 http.Hijacker
180 http.Pusher
181 http.Flusher
182 }{w, hj, pu, fl}
183 case i0 && !i1 && i2 && i3 && i4:
184 return struct {
185 http.ResponseWriter
186 http.Hijacker
187 http.Pusher
188 http.Flusher
189 io.ReaderFrom
190 }{w, hj, pu, fl, rf}
191 case i0 && i1 && !i2 && !i3 && !i4:
192 return struct {
193 http.ResponseWriter
194 http.Hijacker
195 http.CloseNotifier
196 }{w, hj, cn}
197 case i0 && i1 && !i2 && !i3 && i4:
198 return struct {
199 http.ResponseWriter
200 http.Hijacker
201 http.CloseNotifier
202 io.ReaderFrom
203 }{w, hj, cn, rf}
204 case i0 && i1 && !i2 && i3 && !i4:
205 return struct {
206 http.ResponseWriter
207 http.Hijacker
208 http.CloseNotifier
209 http.Flusher
210 }{w, hj, cn, fl}
211 case i0 && i1 && !i2 && i3 && i4:
212 return struct {
213 http.ResponseWriter
214 http.Hijacker
215 http.CloseNotifier
216 http.Flusher
217 io.ReaderFrom
218 }{w, hj, cn, fl, rf}
219 case i0 && i1 && i2 && !i3 && !i4:
220 return struct {
221 http.ResponseWriter
222 http.Hijacker
223 http.CloseNotifier
224 http.Pusher
225 }{w, hj, cn, pu}
226 case i0 && i1 && i2 && !i3 && i4:
227 return struct {
228 http.ResponseWriter
229 http.Hijacker
230 http.CloseNotifier
231 http.Pusher
232 io.ReaderFrom
233 }{w, hj, cn, pu, rf}
234 case i0 && i1 && i2 && i3 && !i4:
235 return struct {
236 http.ResponseWriter
237 http.Hijacker
238 http.CloseNotifier
239 http.Pusher
240 http.Flusher
241 }{w, hj, cn, pu, fl}
242 case i0 && i1 && i2 && i3 && i4:
243 return struct {
244 http.ResponseWriter
245 http.Hijacker
246 http.CloseNotifier
247 http.Pusher
248 http.Flusher
249 io.ReaderFrom
250 }{w, hj, cn, pu, fl, rf}
251 default:
252 return struct {
253 http.ResponseWriter
254 }{w}
255 }
256 }
0 package http
1
2 import (
3 "bufio"
4 "io"
5 "net"
6 "net/http"
7 "testing"
8 )
9
10 type versatileWriter struct {
11 http.ResponseWriter
12 closeNotifyCalled bool
13 hijackCalled bool
14 readFromCalled bool
15 pushCalled bool
16 flushCalled bool
17 }
18
19 func (v *versatileWriter) Flush() { v.flushCalled = true }
20 func (v *versatileWriter) Push(target string, opts *http.PushOptions) error {
21 v.pushCalled = true
22 return nil
23 }
24 func (v *versatileWriter) ReadFrom(r io.Reader) (n int64, err error) {
25 v.readFromCalled = true
26 return 0, nil
27 }
28 func (v *versatileWriter) CloseNotify() <-chan bool { v.closeNotifyCalled = true; return nil }
29 func (v *versatileWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
30 v.hijackCalled = true
31 return nil, nil, nil
32 }
33
34 func TestInterceptingWriter_passthroughs(t *testing.T) {
35 w := &versatileWriter{}
36 iw := (&interceptingWriter{ResponseWriter: w}).reimplementInterfaces()
37 iw.(http.Flusher).Flush()
38 iw.(http.Pusher).Push("", nil)
39 iw.(http.CloseNotifier).CloseNotify()
40 iw.(http.Hijacker).Hijack()
41 iw.(io.ReaderFrom).ReadFrom(nil)
42
43 if !w.flushCalled {
44 t.Error("Flush not called")
45 }
46 if !w.pushCalled {
47 t.Error("Push not called")
48 }
49 if !w.closeNotifyCalled {
50 t.Error("CloseNotify not called")
51 }
52 if !w.hijackCalled {
53 t.Error("Hijack not called")
54 }
55 if !w.readFromCalled {
56 t.Error("ReadFrom not called")
57 }
58 }
59
60 // TestInterceptingWriter_reimplementInterfaces is also derived from
61 // https://github.com/felixge/httpsnoop, like interceptingWriter.
62 func TestInterceptingWriter_reimplementInterfaces(t *testing.T) {
63 // combination 1/32
64 {
65 t.Log("http.ResponseWriter")
66 inner := struct {
67 http.ResponseWriter
68 }{}
69 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
70 if _, ok := w.(http.ResponseWriter); ok != true {
71 t.Error("unexpected interface")
72 }
73 if _, ok := w.(http.Flusher); ok != false {
74 t.Error("unexpected interface")
75 }
76 if _, ok := w.(http.CloseNotifier); ok != false {
77 t.Error("unexpected interface")
78 }
79 if _, ok := w.(http.Hijacker); ok != false {
80 t.Error("unexpected interface")
81 }
82 if _, ok := w.(io.ReaderFrom); ok != false {
83 t.Error("unexpected interface")
84 }
85 if _, ok := w.(http.Pusher); ok != false {
86 t.Error("unexpected interface")
87 }
88
89 }
90
91 // combination 2/32
92 {
93 t.Log("http.ResponseWriter, http.Pusher")
94 inner := struct {
95 http.ResponseWriter
96 http.Pusher
97 }{}
98 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
99 if _, ok := w.(http.ResponseWriter); ok != true {
100 t.Error("unexpected interface")
101 }
102 if _, ok := w.(http.Flusher); ok != false {
103 t.Error("unexpected interface")
104 }
105 if _, ok := w.(http.CloseNotifier); ok != false {
106 t.Error("unexpected interface")
107 }
108 if _, ok := w.(http.Hijacker); ok != false {
109 t.Error("unexpected interface")
110 }
111 if _, ok := w.(io.ReaderFrom); ok != false {
112 t.Error("unexpected interface")
113 }
114 if _, ok := w.(http.Pusher); ok != true {
115 t.Error("unexpected interface")
116 }
117
118 }
119
120 // combination 3/32
121 {
122 t.Log("http.ResponseWriter, io.ReaderFrom")
123 inner := struct {
124 http.ResponseWriter
125 io.ReaderFrom
126 }{}
127 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
128 if _, ok := w.(http.ResponseWriter); ok != true {
129 t.Error("unexpected interface")
130 }
131 if _, ok := w.(http.Flusher); ok != false {
132 t.Error("unexpected interface")
133 }
134 if _, ok := w.(http.CloseNotifier); ok != false {
135 t.Error("unexpected interface")
136 }
137 if _, ok := w.(http.Hijacker); ok != false {
138 t.Error("unexpected interface")
139 }
140 if _, ok := w.(io.ReaderFrom); ok != true {
141 t.Error("unexpected interface")
142 }
143 if _, ok := w.(http.Pusher); ok != false {
144 t.Error("unexpected interface")
145 }
146
147 }
148
149 // combination 4/32
150 {
151 t.Log("http.ResponseWriter, io.ReaderFrom, http.Pusher")
152 inner := struct {
153 http.ResponseWriter
154 io.ReaderFrom
155 http.Pusher
156 }{}
157 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
158 if _, ok := w.(http.ResponseWriter); ok != true {
159 t.Error("unexpected interface")
160 }
161 if _, ok := w.(http.Flusher); ok != false {
162 t.Error("unexpected interface")
163 }
164 if _, ok := w.(http.CloseNotifier); ok != false {
165 t.Error("unexpected interface")
166 }
167 if _, ok := w.(http.Hijacker); ok != false {
168 t.Error("unexpected interface")
169 }
170 if _, ok := w.(io.ReaderFrom); ok != true {
171 t.Error("unexpected interface")
172 }
173 if _, ok := w.(http.Pusher); ok != true {
174 t.Error("unexpected interface")
175 }
176
177 }
178
179 // combination 5/32
180 {
181 t.Log("http.ResponseWriter, http.Hijacker")
182 inner := struct {
183 http.ResponseWriter
184 http.Hijacker
185 }{}
186 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
187 if _, ok := w.(http.ResponseWriter); ok != true {
188 t.Error("unexpected interface")
189 }
190 if _, ok := w.(http.Flusher); ok != false {
191 t.Error("unexpected interface")
192 }
193 if _, ok := w.(http.CloseNotifier); ok != false {
194 t.Error("unexpected interface")
195 }
196 if _, ok := w.(http.Hijacker); ok != true {
197 t.Error("unexpected interface")
198 }
199 if _, ok := w.(io.ReaderFrom); ok != false {
200 t.Error("unexpected interface")
201 }
202 if _, ok := w.(http.Pusher); ok != false {
203 t.Error("unexpected interface")
204 }
205
206 }
207
208 // combination 6/32
209 {
210 t.Log("http.ResponseWriter, http.Hijacker, http.Pusher")
211 inner := struct {
212 http.ResponseWriter
213 http.Hijacker
214 http.Pusher
215 }{}
216 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
217 if _, ok := w.(http.ResponseWriter); ok != true {
218 t.Error("unexpected interface")
219 }
220 if _, ok := w.(http.Flusher); ok != false {
221 t.Error("unexpected interface")
222 }
223 if _, ok := w.(http.CloseNotifier); ok != false {
224 t.Error("unexpected interface")
225 }
226 if _, ok := w.(http.Hijacker); ok != true {
227 t.Error("unexpected interface")
228 }
229 if _, ok := w.(io.ReaderFrom); ok != false {
230 t.Error("unexpected interface")
231 }
232 if _, ok := w.(http.Pusher); ok != true {
233 t.Error("unexpected interface")
234 }
235
236 }
237
238 // combination 7/32
239 {
240 t.Log("http.ResponseWriter, http.Hijacker, io.ReaderFrom")
241 inner := struct {
242 http.ResponseWriter
243 http.Hijacker
244 io.ReaderFrom
245 }{}
246 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
247 if _, ok := w.(http.ResponseWriter); ok != true {
248 t.Error("unexpected interface")
249 }
250 if _, ok := w.(http.Flusher); ok != false {
251 t.Error("unexpected interface")
252 }
253 if _, ok := w.(http.CloseNotifier); ok != false {
254 t.Error("unexpected interface")
255 }
256 if _, ok := w.(http.Hijacker); ok != true {
257 t.Error("unexpected interface")
258 }
259 if _, ok := w.(io.ReaderFrom); ok != true {
260 t.Error("unexpected interface")
261 }
262 if _, ok := w.(http.Pusher); ok != false {
263 t.Error("unexpected interface")
264 }
265
266 }
267
268 // combination 8/32
269 {
270 t.Log("http.ResponseWriter, http.Hijacker, io.ReaderFrom, http.Pusher")
271 inner := struct {
272 http.ResponseWriter
273 http.Hijacker
274 io.ReaderFrom
275 http.Pusher
276 }{}
277 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
278 if _, ok := w.(http.ResponseWriter); ok != true {
279 t.Error("unexpected interface")
280 }
281 if _, ok := w.(http.Flusher); ok != false {
282 t.Error("unexpected interface")
283 }
284 if _, ok := w.(http.CloseNotifier); ok != false {
285 t.Error("unexpected interface")
286 }
287 if _, ok := w.(http.Hijacker); ok != true {
288 t.Error("unexpected interface")
289 }
290 if _, ok := w.(io.ReaderFrom); ok != true {
291 t.Error("unexpected interface")
292 }
293 if _, ok := w.(http.Pusher); ok != true {
294 t.Error("unexpected interface")
295 }
296
297 }
298
299 // combination 9/32
300 {
301 t.Log("http.ResponseWriter, http.CloseNotifier")
302 inner := struct {
303 http.ResponseWriter
304 http.CloseNotifier
305 }{}
306 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
307 if _, ok := w.(http.ResponseWriter); ok != true {
308 t.Error("unexpected interface")
309 }
310 if _, ok := w.(http.Flusher); ok != false {
311 t.Error("unexpected interface")
312 }
313 if _, ok := w.(http.CloseNotifier); ok != true {
314 t.Error("unexpected interface")
315 }
316 if _, ok := w.(http.Hijacker); ok != false {
317 t.Error("unexpected interface")
318 }
319 if _, ok := w.(io.ReaderFrom); ok != false {
320 t.Error("unexpected interface")
321 }
322 if _, ok := w.(http.Pusher); ok != false {
323 t.Error("unexpected interface")
324 }
325
326 }
327
328 // combination 10/32
329 {
330 t.Log("http.ResponseWriter, http.CloseNotifier, http.Pusher")
331 inner := struct {
332 http.ResponseWriter
333 http.CloseNotifier
334 http.Pusher
335 }{}
336 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
337 if _, ok := w.(http.ResponseWriter); ok != true {
338 t.Error("unexpected interface")
339 }
340 if _, ok := w.(http.Flusher); ok != false {
341 t.Error("unexpected interface")
342 }
343 if _, ok := w.(http.CloseNotifier); ok != true {
344 t.Error("unexpected interface")
345 }
346 if _, ok := w.(http.Hijacker); ok != false {
347 t.Error("unexpected interface")
348 }
349 if _, ok := w.(io.ReaderFrom); ok != false {
350 t.Error("unexpected interface")
351 }
352 if _, ok := w.(http.Pusher); ok != true {
353 t.Error("unexpected interface")
354 }
355
356 }
357
358 // combination 11/32
359 {
360 t.Log("http.ResponseWriter, http.CloseNotifier, io.ReaderFrom")
361 inner := struct {
362 http.ResponseWriter
363 http.CloseNotifier
364 io.ReaderFrom
365 }{}
366 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
367 if _, ok := w.(http.ResponseWriter); ok != true {
368 t.Error("unexpected interface")
369 }
370 if _, ok := w.(http.Flusher); ok != false {
371 t.Error("unexpected interface")
372 }
373 if _, ok := w.(http.CloseNotifier); ok != true {
374 t.Error("unexpected interface")
375 }
376 if _, ok := w.(http.Hijacker); ok != false {
377 t.Error("unexpected interface")
378 }
379 if _, ok := w.(io.ReaderFrom); ok != true {
380 t.Error("unexpected interface")
381 }
382 if _, ok := w.(http.Pusher); ok != false {
383 t.Error("unexpected interface")
384 }
385
386 }
387
388 // combination 12/32
389 {
390 t.Log("http.ResponseWriter, http.CloseNotifier, io.ReaderFrom, http.Pusher")
391 inner := struct {
392 http.ResponseWriter
393 http.CloseNotifier
394 io.ReaderFrom
395 http.Pusher
396 }{}
397 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
398 if _, ok := w.(http.ResponseWriter); ok != true {
399 t.Error("unexpected interface")
400 }
401 if _, ok := w.(http.Flusher); ok != false {
402 t.Error("unexpected interface")
403 }
404 if _, ok := w.(http.CloseNotifier); ok != true {
405 t.Error("unexpected interface")
406 }
407 if _, ok := w.(http.Hijacker); ok != false {
408 t.Error("unexpected interface")
409 }
410 if _, ok := w.(io.ReaderFrom); ok != true {
411 t.Error("unexpected interface")
412 }
413 if _, ok := w.(http.Pusher); ok != true {
414 t.Error("unexpected interface")
415 }
416
417 }
418
419 // combination 13/32
420 {
421 t.Log("http.ResponseWriter, http.CloseNotifier, http.Hijacker")
422 inner := struct {
423 http.ResponseWriter
424 http.CloseNotifier
425 http.Hijacker
426 }{}
427 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
428 if _, ok := w.(http.ResponseWriter); ok != true {
429 t.Error("unexpected interface")
430 }
431 if _, ok := w.(http.Flusher); ok != false {
432 t.Error("unexpected interface")
433 }
434 if _, ok := w.(http.CloseNotifier); ok != true {
435 t.Error("unexpected interface")
436 }
437 if _, ok := w.(http.Hijacker); ok != true {
438 t.Error("unexpected interface")
439 }
440 if _, ok := w.(io.ReaderFrom); ok != false {
441 t.Error("unexpected interface")
442 }
443 if _, ok := w.(http.Pusher); ok != false {
444 t.Error("unexpected interface")
445 }
446
447 }
448
449 // combination 14/32
450 {
451 t.Log("http.ResponseWriter, http.CloseNotifier, http.Hijacker, http.Pusher")
452 inner := struct {
453 http.ResponseWriter
454 http.CloseNotifier
455 http.Hijacker
456 http.Pusher
457 }{}
458 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
459 if _, ok := w.(http.ResponseWriter); ok != true {
460 t.Error("unexpected interface")
461 }
462 if _, ok := w.(http.Flusher); ok != false {
463 t.Error("unexpected interface")
464 }
465 if _, ok := w.(http.CloseNotifier); ok != true {
466 t.Error("unexpected interface")
467 }
468 if _, ok := w.(http.Hijacker); ok != true {
469 t.Error("unexpected interface")
470 }
471 if _, ok := w.(io.ReaderFrom); ok != false {
472 t.Error("unexpected interface")
473 }
474 if _, ok := w.(http.Pusher); ok != true {
475 t.Error("unexpected interface")
476 }
477
478 }
479
480 // combination 15/32
481 {
482 t.Log("http.ResponseWriter, http.CloseNotifier, http.Hijacker, io.ReaderFrom")
483 inner := struct {
484 http.ResponseWriter
485 http.CloseNotifier
486 http.Hijacker
487 io.ReaderFrom
488 }{}
489 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
490 if _, ok := w.(http.ResponseWriter); ok != true {
491 t.Error("unexpected interface")
492 }
493 if _, ok := w.(http.Flusher); ok != false {
494 t.Error("unexpected interface")
495 }
496 if _, ok := w.(http.CloseNotifier); ok != true {
497 t.Error("unexpected interface")
498 }
499 if _, ok := w.(http.Hijacker); ok != true {
500 t.Error("unexpected interface")
501 }
502 if _, ok := w.(io.ReaderFrom); ok != true {
503 t.Error("unexpected interface")
504 }
505 if _, ok := w.(http.Pusher); ok != false {
506 t.Error("unexpected interface")
507 }
508
509 }
510
511 // combination 16/32
512 {
513 t.Log("http.ResponseWriter, http.CloseNotifier, http.Hijacker, io.ReaderFrom, http.Pusher")
514 inner := struct {
515 http.ResponseWriter
516 http.CloseNotifier
517 http.Hijacker
518 io.ReaderFrom
519 http.Pusher
520 }{}
521 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
522 if _, ok := w.(http.ResponseWriter); ok != true {
523 t.Error("unexpected interface")
524 }
525 if _, ok := w.(http.Flusher); ok != false {
526 t.Error("unexpected interface")
527 }
528 if _, ok := w.(http.CloseNotifier); ok != true {
529 t.Error("unexpected interface")
530 }
531 if _, ok := w.(http.Hijacker); ok != true {
532 t.Error("unexpected interface")
533 }
534 if _, ok := w.(io.ReaderFrom); ok != true {
535 t.Error("unexpected interface")
536 }
537 if _, ok := w.(http.Pusher); ok != true {
538 t.Error("unexpected interface")
539 }
540
541 }
542
543 // combination 17/32
544 {
545 t.Log("http.ResponseWriter, http.Flusher")
546 inner := struct {
547 http.ResponseWriter
548 http.Flusher
549 }{}
550 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
551 if _, ok := w.(http.ResponseWriter); ok != true {
552 t.Error("unexpected interface")
553 }
554 if _, ok := w.(http.Flusher); ok != true {
555 t.Error("unexpected interface")
556 }
557 if _, ok := w.(http.CloseNotifier); ok != false {
558 t.Error("unexpected interface")
559 }
560 if _, ok := w.(http.Hijacker); ok != false {
561 t.Error("unexpected interface")
562 }
563 if _, ok := w.(io.ReaderFrom); ok != false {
564 t.Error("unexpected interface")
565 }
566 if _, ok := w.(http.Pusher); ok != false {
567 t.Error("unexpected interface")
568 }
569
570 }
571
572 // combination 18/32
573 {
574 t.Log("http.ResponseWriter, http.Flusher, http.Pusher")
575 inner := struct {
576 http.ResponseWriter
577 http.Flusher
578 http.Pusher
579 }{}
580 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
581 if _, ok := w.(http.ResponseWriter); ok != true {
582 t.Error("unexpected interface")
583 }
584 if _, ok := w.(http.Flusher); ok != true {
585 t.Error("unexpected interface")
586 }
587 if _, ok := w.(http.CloseNotifier); ok != false {
588 t.Error("unexpected interface")
589 }
590 if _, ok := w.(http.Hijacker); ok != false {
591 t.Error("unexpected interface")
592 }
593 if _, ok := w.(io.ReaderFrom); ok != false {
594 t.Error("unexpected interface")
595 }
596 if _, ok := w.(http.Pusher); ok != true {
597 t.Error("unexpected interface")
598 }
599
600 }
601
602 // combination 19/32
603 {
604 t.Log("http.ResponseWriter, http.Flusher, io.ReaderFrom")
605 inner := struct {
606 http.ResponseWriter
607 http.Flusher
608 io.ReaderFrom
609 }{}
610 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
611 if _, ok := w.(http.ResponseWriter); ok != true {
612 t.Error("unexpected interface")
613 }
614 if _, ok := w.(http.Flusher); ok != true {
615 t.Error("unexpected interface")
616 }
617 if _, ok := w.(http.CloseNotifier); ok != false {
618 t.Error("unexpected interface")
619 }
620 if _, ok := w.(http.Hijacker); ok != false {
621 t.Error("unexpected interface")
622 }
623 if _, ok := w.(io.ReaderFrom); ok != true {
624 t.Error("unexpected interface")
625 }
626 if _, ok := w.(http.Pusher); ok != false {
627 t.Error("unexpected interface")
628 }
629
630 }
631
632 // combination 20/32
633 {
634 t.Log("http.ResponseWriter, http.Flusher, io.ReaderFrom, http.Pusher")
635 inner := struct {
636 http.ResponseWriter
637 http.Flusher
638 io.ReaderFrom
639 http.Pusher
640 }{}
641 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
642 if _, ok := w.(http.ResponseWriter); ok != true {
643 t.Error("unexpected interface")
644 }
645 if _, ok := w.(http.Flusher); ok != true {
646 t.Error("unexpected interface")
647 }
648 if _, ok := w.(http.CloseNotifier); ok != false {
649 t.Error("unexpected interface")
650 }
651 if _, ok := w.(http.Hijacker); ok != false {
652 t.Error("unexpected interface")
653 }
654 if _, ok := w.(io.ReaderFrom); ok != true {
655 t.Error("unexpected interface")
656 }
657 if _, ok := w.(http.Pusher); ok != true {
658 t.Error("unexpected interface")
659 }
660
661 }
662
663 // combination 21/32
664 {
665 t.Log("http.ResponseWriter, http.Flusher, http.Hijacker")
666 inner := struct {
667 http.ResponseWriter
668 http.Flusher
669 http.Hijacker
670 }{}
671 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
672 if _, ok := w.(http.ResponseWriter); ok != true {
673 t.Error("unexpected interface")
674 }
675 if _, ok := w.(http.Flusher); ok != true {
676 t.Error("unexpected interface")
677 }
678 if _, ok := w.(http.CloseNotifier); ok != false {
679 t.Error("unexpected interface")
680 }
681 if _, ok := w.(http.Hijacker); ok != true {
682 t.Error("unexpected interface")
683 }
684 if _, ok := w.(io.ReaderFrom); ok != false {
685 t.Error("unexpected interface")
686 }
687 if _, ok := w.(http.Pusher); ok != false {
688 t.Error("unexpected interface")
689 }
690
691 }
692
693 // combination 22/32
694 {
695 t.Log("http.ResponseWriter, http.Flusher, http.Hijacker, http.Pusher")
696 inner := struct {
697 http.ResponseWriter
698 http.Flusher
699 http.Hijacker
700 http.Pusher
701 }{}
702 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
703 if _, ok := w.(http.ResponseWriter); ok != true {
704 t.Error("unexpected interface")
705 }
706 if _, ok := w.(http.Flusher); ok != true {
707 t.Error("unexpected interface")
708 }
709 if _, ok := w.(http.CloseNotifier); ok != false {
710 t.Error("unexpected interface")
711 }
712 if _, ok := w.(http.Hijacker); ok != true {
713 t.Error("unexpected interface")
714 }
715 if _, ok := w.(io.ReaderFrom); ok != false {
716 t.Error("unexpected interface")
717 }
718 if _, ok := w.(http.Pusher); ok != true {
719 t.Error("unexpected interface")
720 }
721
722 }
723
724 // combination 23/32
725 {
726 t.Log("http.ResponseWriter, http.Flusher, http.Hijacker, io.ReaderFrom")
727 inner := struct {
728 http.ResponseWriter
729 http.Flusher
730 http.Hijacker
731 io.ReaderFrom
732 }{}
733 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
734 if _, ok := w.(http.ResponseWriter); ok != true {
735 t.Error("unexpected interface")
736 }
737 if _, ok := w.(http.Flusher); ok != true {
738 t.Error("unexpected interface")
739 }
740 if _, ok := w.(http.CloseNotifier); ok != false {
741 t.Error("unexpected interface")
742 }
743 if _, ok := w.(http.Hijacker); ok != true {
744 t.Error("unexpected interface")
745 }
746 if _, ok := w.(io.ReaderFrom); ok != true {
747 t.Error("unexpected interface")
748 }
749 if _, ok := w.(http.Pusher); ok != false {
750 t.Error("unexpected interface")
751 }
752
753 }
754
755 // combination 24/32
756 {
757 t.Log("http.ResponseWriter, http.Flusher, http.Hijacker, io.ReaderFrom, http.Pusher")
758 inner := struct {
759 http.ResponseWriter
760 http.Flusher
761 http.Hijacker
762 io.ReaderFrom
763 http.Pusher
764 }{}
765 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
766 if _, ok := w.(http.ResponseWriter); ok != true {
767 t.Error("unexpected interface")
768 }
769 if _, ok := w.(http.Flusher); ok != true {
770 t.Error("unexpected interface")
771 }
772 if _, ok := w.(http.CloseNotifier); ok != false {
773 t.Error("unexpected interface")
774 }
775 if _, ok := w.(http.Hijacker); ok != true {
776 t.Error("unexpected interface")
777 }
778 if _, ok := w.(io.ReaderFrom); ok != true {
779 t.Error("unexpected interface")
780 }
781 if _, ok := w.(http.Pusher); ok != true {
782 t.Error("unexpected interface")
783 }
784
785 }
786
787 // combination 25/32
788 {
789 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier")
790 inner := struct {
791 http.ResponseWriter
792 http.Flusher
793 http.CloseNotifier
794 }{}
795 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
796 if _, ok := w.(http.ResponseWriter); ok != true {
797 t.Error("unexpected interface")
798 }
799 if _, ok := w.(http.Flusher); ok != true {
800 t.Error("unexpected interface")
801 }
802 if _, ok := w.(http.CloseNotifier); ok != true {
803 t.Error("unexpected interface")
804 }
805 if _, ok := w.(http.Hijacker); ok != false {
806 t.Error("unexpected interface")
807 }
808 if _, ok := w.(io.ReaderFrom); ok != false {
809 t.Error("unexpected interface")
810 }
811 if _, ok := w.(http.Pusher); ok != false {
812 t.Error("unexpected interface")
813 }
814
815 }
816
817 // combination 26/32
818 {
819 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, http.Pusher")
820 inner := struct {
821 http.ResponseWriter
822 http.Flusher
823 http.CloseNotifier
824 http.Pusher
825 }{}
826 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
827 if _, ok := w.(http.ResponseWriter); ok != true {
828 t.Error("unexpected interface")
829 }
830 if _, ok := w.(http.Flusher); ok != true {
831 t.Error("unexpected interface")
832 }
833 if _, ok := w.(http.CloseNotifier); ok != true {
834 t.Error("unexpected interface")
835 }
836 if _, ok := w.(http.Hijacker); ok != false {
837 t.Error("unexpected interface")
838 }
839 if _, ok := w.(io.ReaderFrom); ok != false {
840 t.Error("unexpected interface")
841 }
842 if _, ok := w.(http.Pusher); ok != true {
843 t.Error("unexpected interface")
844 }
845
846 }
847
848 // combination 27/32
849 {
850 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, io.ReaderFrom")
851 inner := struct {
852 http.ResponseWriter
853 http.Flusher
854 http.CloseNotifier
855 io.ReaderFrom
856 }{}
857 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
858 if _, ok := w.(http.ResponseWriter); ok != true {
859 t.Error("unexpected interface")
860 }
861 if _, ok := w.(http.Flusher); ok != true {
862 t.Error("unexpected interface")
863 }
864 if _, ok := w.(http.CloseNotifier); ok != true {
865 t.Error("unexpected interface")
866 }
867 if _, ok := w.(http.Hijacker); ok != false {
868 t.Error("unexpected interface")
869 }
870 if _, ok := w.(io.ReaderFrom); ok != true {
871 t.Error("unexpected interface")
872 }
873 if _, ok := w.(http.Pusher); ok != false {
874 t.Error("unexpected interface")
875 }
876
877 }
878
879 // combination 28/32
880 {
881 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, io.ReaderFrom, http.Pusher")
882 inner := struct {
883 http.ResponseWriter
884 http.Flusher
885 http.CloseNotifier
886 io.ReaderFrom
887 http.Pusher
888 }{}
889 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
890 if _, ok := w.(http.ResponseWriter); ok != true {
891 t.Error("unexpected interface")
892 }
893 if _, ok := w.(http.Flusher); ok != true {
894 t.Error("unexpected interface")
895 }
896 if _, ok := w.(http.CloseNotifier); ok != true {
897 t.Error("unexpected interface")
898 }
899 if _, ok := w.(http.Hijacker); ok != false {
900 t.Error("unexpected interface")
901 }
902 if _, ok := w.(io.ReaderFrom); ok != true {
903 t.Error("unexpected interface")
904 }
905 if _, ok := w.(http.Pusher); ok != true {
906 t.Error("unexpected interface")
907 }
908
909 }
910
911 // combination 29/32
912 {
913 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, http.Hijacker")
914 inner := struct {
915 http.ResponseWriter
916 http.Flusher
917 http.CloseNotifier
918 http.Hijacker
919 }{}
920 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
921 if _, ok := w.(http.ResponseWriter); ok != true {
922 t.Error("unexpected interface")
923 }
924 if _, ok := w.(http.Flusher); ok != true {
925 t.Error("unexpected interface")
926 }
927 if _, ok := w.(http.CloseNotifier); ok != true {
928 t.Error("unexpected interface")
929 }
930 if _, ok := w.(http.Hijacker); ok != true {
931 t.Error("unexpected interface")
932 }
933 if _, ok := w.(io.ReaderFrom); ok != false {
934 t.Error("unexpected interface")
935 }
936 if _, ok := w.(http.Pusher); ok != false {
937 t.Error("unexpected interface")
938 }
939
940 }
941
942 // combination 30/32
943 {
944 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, http.Hijacker, http.Pusher")
945 inner := struct {
946 http.ResponseWriter
947 http.Flusher
948 http.CloseNotifier
949 http.Hijacker
950 http.Pusher
951 }{}
952 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
953 if _, ok := w.(http.ResponseWriter); ok != true {
954 t.Error("unexpected interface")
955 }
956 if _, ok := w.(http.Flusher); ok != true {
957 t.Error("unexpected interface")
958 }
959 if _, ok := w.(http.CloseNotifier); ok != true {
960 t.Error("unexpected interface")
961 }
962 if _, ok := w.(http.Hijacker); ok != true {
963 t.Error("unexpected interface")
964 }
965 if _, ok := w.(io.ReaderFrom); ok != false {
966 t.Error("unexpected interface")
967 }
968 if _, ok := w.(http.Pusher); ok != true {
969 t.Error("unexpected interface")
970 }
971
972 }
973
974 // combination 31/32
975 {
976 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, http.Hijacker, io.ReaderFrom")
977 inner := struct {
978 http.ResponseWriter
979 http.Flusher
980 http.CloseNotifier
981 http.Hijacker
982 io.ReaderFrom
983 }{}
984 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
985 if _, ok := w.(http.ResponseWriter); ok != true {
986 t.Error("unexpected interface")
987 }
988 if _, ok := w.(http.Flusher); ok != true {
989 t.Error("unexpected interface")
990 }
991 if _, ok := w.(http.CloseNotifier); ok != true {
992 t.Error("unexpected interface")
993 }
994 if _, ok := w.(http.Hijacker); ok != true {
995 t.Error("unexpected interface")
996 }
997 if _, ok := w.(io.ReaderFrom); ok != true {
998 t.Error("unexpected interface")
999 }
1000 if _, ok := w.(http.Pusher); ok != false {
1001 t.Error("unexpected interface")
1002 }
1003
1004 }
1005
1006 // combination 32/32
1007 {
1008 t.Log("http.ResponseWriter, http.Flusher, http.CloseNotifier, http.Hijacker, io.ReaderFrom, http.Pusher")
1009 inner := struct {
1010 http.ResponseWriter
1011 http.Flusher
1012 http.CloseNotifier
1013 http.Hijacker
1014 io.ReaderFrom
1015 http.Pusher
1016 }{}
1017 w := (&interceptingWriter{ResponseWriter: inner}).reimplementInterfaces()
1018 if _, ok := w.(http.ResponseWriter); ok != true {
1019 t.Error("unexpected interface")
1020 }
1021 if _, ok := w.(http.Flusher); ok != true {
1022 t.Error("unexpected interface")
1023 }
1024 if _, ok := w.(http.CloseNotifier); ok != true {
1025 t.Error("unexpected interface")
1026 }
1027 if _, ok := w.(http.Hijacker); ok != true {
1028 t.Error("unexpected interface")
1029 }
1030 if _, ok := w.(io.ReaderFrom); ok != true {
1031 t.Error("unexpected interface")
1032 }
1033 if _, ok := w.(http.Pusher); ok != true {
1034 t.Error("unexpected interface")
1035 }
1036
1037 }
1038 }
103103 f(ctx, iw.code, r)
104104 }
105105 }()
106 w = iw
106 w = iw.reimplementInterfaces()
107107 }
108108
109109 for _, f := range s.before {
222222 type Headerer interface {
223223 Headers() http.Header
224224 }
225
226 type interceptingWriter struct {
227 http.ResponseWriter
228 code int
229 written int64
230 }
231
232 // WriteHeader may not be explicitly called, so care must be taken to
233 // initialize w.code to its default value of http.StatusOK.
234 func (w *interceptingWriter) WriteHeader(code int) {
235 w.code = code
236 w.ResponseWriter.WriteHeader(code)
237 }
238
239 func (w *interceptingWriter) Write(p []byte) (int, error) {
240 n, err := w.ResponseWriter.Write(p)
241 w.written += int64(n)
242 return n, err
243 }