github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/go-chi/chi/middleware/wrap_writer18.go (about) 1 //go:build go1.8 || appengine 2 // +build go1.8 appengine 3 4 package middleware 5 6 import ( 7 "io" 8 9 "github.com/hellobchain/newcryptosm/http" 10 ) 11 12 // NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to 13 // hook into various parts of the response process. 14 func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter { 15 _, cn := w.(http.CloseNotifier) 16 _, fl := w.(http.Flusher) 17 18 bw := basicWriter{ResponseWriter: w} 19 20 if protoMajor == 2 { 21 _, ps := w.(http.Pusher) 22 if cn && fl && ps { 23 return &http2FancyWriter{bw} 24 } 25 } else { 26 _, hj := w.(http.Hijacker) 27 _, rf := w.(io.ReaderFrom) 28 if cn && fl && hj && rf { 29 return &httpFancyWriter{bw} 30 } 31 } 32 if fl { 33 return &flushWriter{bw} 34 } 35 36 return &bw 37 } 38 39 func (f *http2FancyWriter) Push(target string, opts *http.PushOptions) error { 40 return f.basicWriter.ResponseWriter.(http.Pusher).Push(target, opts) 41 } 42 43 var _ http.Pusher = &http2FancyWriter{}