internal

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResponseRecorder

type ResponseRecorder struct {
	http.ResponseWriter

	// BeforeWriteHeader, when set, is called once just before the status line
	// and headers are written to the real writer. It is the last chance to add
	// headers such as ETag or X-Cache.
	BeforeWriteHeader func(http.Header)
	// contains filtered or unexported fields
}

ResponseRecorder buffers a response so a middleware can inspect and modify it before anything is sent to the client.

The recorder holds at most Limit bytes. If the handler writes more than that, the recorder flushes what it has and switches to pass-through mode; the response is streamed normally and Buffered reports false. Calling Flush or Hijack also disables buffering, which keeps SSE, websockets, and other streaming handlers working.

A middleware must call Commit to send a fully buffered response, or Discard to throw it away (for example when the handler returns an error and Echo should render its own error response).

ResponseRecorder implements Unwrap so it plays well with http.ResponseController and Echo's response-writer contract.

func NewResponseRecorder

func NewResponseRecorder(w http.ResponseWriter, limit int) *ResponseRecorder

NewResponseRecorder wraps w and buffers up to limit bytes. A limit <= 0 disables buffering entirely: the first write goes straight to w.

func (*ResponseRecorder) Body

func (r *ResponseRecorder) Body() []byte

Body returns a copy of the buffered body.

func (*ResponseRecorder) Buffered

func (r *ResponseRecorder) Buffered() bool

Buffered reports whether the response is still being buffered.

func (*ResponseRecorder) Commit

func (r *ResponseRecorder) Commit() error

Commit flushes a buffered response to the client. It is a no-op when the response was streamed, hijacked, or discarded.

func (*ResponseRecorder) Discard

func (r *ResponseRecorder) Discard()

Discard drops the buffered response and prevents it from being committed. Headers already set on the underlying writer are left alone.

func (*ResponseRecorder) Flush

func (r *ResponseRecorder) Flush()

Flush sends the status, headers, and buffered body, then flushes the underlying writer. It permanently disables buffering for this response.

func (*ResponseRecorder) FlushError

func (r *ResponseRecorder) FlushError() error

FlushError is the http.ResponseController-compatible variant of Flush.

func (*ResponseRecorder) Hijack

func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack lets the handler take over the connection (websockets). Buffered data is discarded and no HTTP response is written.

func (*ResponseRecorder) Hijacked

func (r *ResponseRecorder) Hijacked() bool

Hijacked reports whether the handler took over the connection.

func (*ResponseRecorder) Overflowed

func (r *ResponseRecorder) Overflowed() bool

Overflowed reports whether the buffer limit was exceeded.

func (*ResponseRecorder) Passthrough

func (r *ResponseRecorder) Passthrough() bool

Passthrough reports whether the response was streamed because it exceeded the buffer limit or the handler flushed it.

func (*ResponseRecorder) Push

func (r *ResponseRecorder) Push(target string, opts *http.PushOptions) error

Push implements http.Pusher when the underlying writer supports HTTP/2 server push.

func (*ResponseRecorder) Status

func (r *ResponseRecorder) Status() int

Status returns the recorded status code.

func (*ResponseRecorder) Unwrap

func (r *ResponseRecorder) Unwrap() http.ResponseWriter

Unwrap returns the wrapped writer. Echo v5 uses this to reach the original *echo.Response and http.ResponseController uses it for optional interfaces.

func (*ResponseRecorder) Write

func (r *ResponseRecorder) Write(p []byte) (int, error)

Write stores the body in the buffer, or streams it once the limit is exceeded.

func (*ResponseRecorder) WriteHeader

func (r *ResponseRecorder) WriteHeader(code int)

WriteHeader records the status code. It is not sent to the client until Commit, a buffer overflow, or Flush.

Jump to

Keyboard shortcuts

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