Documentation
¶
Overview ¶
Package onfinished registers callbacks that run when an HTTP response finishes, mirroring the behavior of the npm on-finished library in an idiomatic, httptest-friendly way.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tracker ¶
type Tracker struct {
http.ResponseWriter
// contains filtered or unexported fields
}
Tracker wraps an http.ResponseWriter and tracks whether the response has finished. Callbacks registered via OnFinished are invoked once when Done is called.
func New ¶
func New(w http.ResponseWriter) *Tracker
New wraps w in a Tracker. The returned Tracker implements http.ResponseWriter and passes WriteHeader, Write, and Flush through to w.
func (*Tracker) Done ¶
Done marks the response as finished and invokes all registered callbacks with err. It is idempotent: subsequent calls do nothing.
func (*Tracker) Flush ¶
func (t *Tracker) Flush()
Flush implements http.Flusher when the underlying ResponseWriter supports it; otherwise it is a no-op.
func (*Tracker) IsFinished ¶
IsFinished reports whether the response has finished.
func (*Tracker) OnFinished ¶
OnFinished registers fn to be called when the response finishes. If the response has already finished, fn is invoked immediately with the recorded error.