capturewriter

package module
v0.0.0-...-2668d27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL