type UserProvidedDecorator … // WrapForHTTP1Or2 accepts a user-provided decorator of an "inner" http.responseWriter // object and potentially wraps the user-provided decorator with a new http.ResponseWriter // object that implements http.CloseNotifier, http.Flusher, and/or http.Hijacker by // delegating to the user-provided decorator (if it implements the relevant method) or // the inner http.ResponseWriter (otherwise), so that the returned http.ResponseWriter // object implements the same subset of those interfaces as the inner http.ResponseWriter. // // This function handles the following three casses. // - The inner ResponseWriter implements `http.CloseNotifier`, `http.Flusher`, // and `http.Hijacker` (an HTTP/1.1 sever provides such a ResponseWriter). // - The inner ResponseWriter implements `http.CloseNotifier` and `http.Flusher` // but not `http.Hijacker` (an HTTP/2 server provides such a ResponseWriter). // - All the other cases collapse to this one, in which the given ResponseWriter is returned. // // There are three applicable terms: // - "outer": this is the ResponseWriter object returned by the WrapForHTTP1Or2 function. // - "user-provided decorator" or "middle": this is the user-provided decorator // that decorates an inner ResponseWriter object. A user-provided decorator // implements the UserProvidedDecorator interface. A user-provided decorator // may or may not implement http.CloseNotifier, http.Flusher or http.Hijacker. // - "inner": the ResponseWriter that the user-provided decorator extends. func WrapForHTTP1Or2(decorator UserProvidedDecorator) http.ResponseWriter { … } type CloseNotifierFlusher … // GetOriginal goes through the chain of wrapped http.ResponseWriter objects // and returns the original http.ResponseWriter object provided to the first // request handler in the filter chain. func GetOriginal(w http.ResponseWriter) http.ResponseWriter { … } var _ … var _ … var _ … var _ … type outerWithCloseNotifyAndFlush … func (wr outerWithCloseNotifyAndFlush) CloseNotify() <-chan bool { … } func (wr outerWithCloseNotifyAndFlush) Flush() { … } var _ … var _ … var _ … var _ … var _ … type outerWithCloseNotifyFlushAndHijack … func (wr outerWithCloseNotifyFlushAndHijack) Hijack() (net.Conn, *bufio.ReadWriter, error) { … }