Documentation ¶
Index ¶
- func GetOriginal(w http.ResponseWriter) http.ResponseWriter
- func WrapForHTTP1Or2(decorator UserProvidedDecorator) http.ResponseWriter
- type CloseNotifierFlusher
- type FakeResponseWriter
- type FakeResponseWriterFlusherCloseNotifier
- type FakeResponseWriterFlusherCloseNotifierHijacker
- type UserProvidedDecorator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOriginal ¶
func GetOriginal(w http.ResponseWriter) http.ResponseWriter
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 WrapForHTTP1Or2 ¶
func WrapForHTTP1Or2(decorator UserProvidedDecorator) http.ResponseWriter
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.
Types ¶
type CloseNotifierFlusher ¶
type CloseNotifierFlusher interface { http.CloseNotifier http.Flusher }
CloseNotifierFlusher is a combination of http.CloseNotifier and http.Flusher This applies to both http/1.x and http2 requests.
type FakeResponseWriter ¶
type FakeResponseWriter struct{}
FakeResponseWriter implements http.ResponseWriter, it is used for testing purpose only
func (*FakeResponseWriter) Header ¶
func (fw *FakeResponseWriter) Header() http.Header
func (*FakeResponseWriter) WriteHeader ¶
func (fw *FakeResponseWriter) WriteHeader(code int)
type FakeResponseWriterFlusherCloseNotifier ¶
type FakeResponseWriterFlusherCloseNotifier struct {
*FakeResponseWriter
}
For HTTP2 an http.ResponseWriter object implements http.Flusher and http.CloseNotifier. It is used for testing purpose only
func (*FakeResponseWriterFlusherCloseNotifier) CloseNotify ¶
func (fw *FakeResponseWriterFlusherCloseNotifier) CloseNotify() <-chan bool
func (*FakeResponseWriterFlusherCloseNotifier) Flush ¶
func (fw *FakeResponseWriterFlusherCloseNotifier) Flush()
type FakeResponseWriterFlusherCloseNotifierHijacker ¶
type FakeResponseWriterFlusherCloseNotifierHijacker struct {
*FakeResponseWriterFlusherCloseNotifier
}
For HTTP/1.x an http.ResponseWriter object implements http.Flusher, http.CloseNotifier and http.Hijacker. It is used for testing purpose only
func (*FakeResponseWriterFlusherCloseNotifierHijacker) Hijack ¶
func (fw *FakeResponseWriterFlusherCloseNotifierHijacker) Hijack() (net.Conn, *bufio.ReadWriter, error)
type UserProvidedDecorator ¶
type UserProvidedDecorator interface { http.ResponseWriter // Unwrap returns the inner http.ResponseWriter object associated // with the user-provided decorator. Unwrap() http.ResponseWriter }
UserProvidedDecorator represensts a user (client that uses this package) provided decorator that wraps an inner http.ResponseWriter object. The user-provided decorator object must return the inner (decorated) http.ResponseWriter object via the Unwrap function.