NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.
(w http.ResponseWriter, protoMajor int)
| 13 | // NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to |
| 14 | // hook into various parts of the response process. |
| 15 | func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter { |
| 16 | _, fl := w.(http.Flusher) |
| 17 | |
| 18 | bw := basicWriter{ResponseWriter: w} |
| 19 | |
| 20 | if protoMajor == 2 { |
| 21 | _, ps := w.(http.Pusher) |
| 22 | if fl && ps { |
| 23 | return &http2FancyWriter{bw} |
| 24 | } |
| 25 | } else { |
| 26 | _, hj := w.(http.Hijacker) |
| 27 | _, rf := w.(io.ReaderFrom) |
| 28 | if fl && hj && rf { |
| 29 | return &httpFancyWriter{bw} |
| 30 | } |
| 31 | if fl && hj { |
| 32 | return &flushHijackWriter{bw} |
| 33 | } |
| 34 | if hj { |
| 35 | return &hijackWriter{bw} |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if fl { |
| 40 | return &flushWriter{bw} |
| 41 | } |
| 42 | |
| 43 | return &bw |
| 44 | } |
| 45 | |
| 46 | // WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook |
| 47 | // into various parts of the response process. |
no outgoing calls