Documentation
¶
Index ¶
- type CaptureWriter
- func (cw *CaptureWriter) Flush()
- func (cw *CaptureWriter) Header() http.Header
- func (cw *CaptureWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (cw *CaptureWriter) Push(target string, opts *http.PushOptions) error
- func (cw *CaptureWriter) Write(body []byte) (int, error)
- func (cw *CaptureWriter) WriteHeader(code int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CaptureWriter ¶
type CaptureWriter struct {
Writer http.ResponseWriter
Code int
Body string
Mu sync.Mutex
PassThrough bool
}
A CaptureWriter wraps a http.ResponseWriter in order to capture HTTP the response code & body that handlers will set. We do this to allow reading these values after they have been set, as this is not normally possible on a ResponseWriter.
func New ¶
func New(w http.ResponseWriter) *CaptureWriter
New creates, instantiates, and returns a new CaptureWriter.
func (*CaptureWriter) Flush ¶
func (cw *CaptureWriter) Flush()
Flush implements the Flusher interface.
func (*CaptureWriter) Header ¶
func (cw *CaptureWriter) Header() http.Header
Header implements part of the http.ResponseWriter interface. We simply pass this to the underlying ResponseWriter, as you can already retrieve a Header from that.
func (*CaptureWriter) Hijack ¶
func (cw *CaptureWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack implements the Hijacker interface.
func (*CaptureWriter) Push ¶
func (cw *CaptureWriter) Push(target string, opts *http.PushOptions) error
Push implements the Pusher interface.
func (*CaptureWriter) Write ¶
func (cw *CaptureWriter) Write(body []byte) (int, error)
Write implements part of the http.ResponseWriter interface. We override it here in order to store the response body, before optionally writing to the underlying ResponseWriter.
func (*CaptureWriter) WriteHeader ¶
func (cw *CaptureWriter) WriteHeader(code int)
WriteHeader implements part of the http.ResponseWriter interface. We override it here in order to store the response code, before optionally writing to the underlying ResponseWriter.