github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/go-chi/chi/middleware/wrap_writer17.go (about)

     1  //go:build go1.7 && !go1.8
     2  // +build go1.7,!go1.8
     3  
     4  package middleware
     5  
     6  import (
     7  	"github.com/hellobchain/newcryptosm/http"
     8  	"io"
     9  )
    10  
    11  // NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
    12  // hook into various parts of the response process.
    13  func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
    14  	_, cn := w.(http.CloseNotifier)
    15  	_, fl := w.(http.Flusher)
    16  
    17  	bw := basicWriter{ResponseWriter: w}
    18  
    19  	if protoMajor == 2 {
    20  		if cn && fl {
    21  			return &http2FancyWriter{bw}
    22  		}
    23  	} else {
    24  		_, hj := w.(http.Hijacker)
    25  		_, rf := w.(io.ReaderFrom)
    26  		if cn && fl && hj && rf {
    27  			return &httpFancyWriter{bw}
    28  		}
    29  	}
    30  	if fl {
    31  		return &flushWriter{bw}
    32  	}
    33  
    34  	return &bw
    35  }