reqlog

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 4 Imported by: ? 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

Overview

Package reqlog is the live view of requests crossing a tunnel.

Both ends see the same request and can report it: the hub as it proxies (revproxy.WithRequestHook) and the peer as it serves (dial.Options.RequestHook). Neither stores anything. A hook is called once per request, after the response, and whatever it does with the event is the application's business: print it, count it, ship it somewhere.

The holt CLI uses it for the line `holt expose` and `holt hub` print as traffic goes through, which is the whole point: a tunnel you cannot watch is hard to trust.

Index

Constants

View Source
const DefaultRecent = 100

DefaultRecent is how many events a new watcher is replayed when the broker is built with 0. Enough to fill a console panel, small enough to forget.

Variables

This section is empty.

Functions

func Middleware

func Middleware(hook Hook, next http.Handler) http.Handler

Middleware wraps a handler so every request it serves is reported. It is what the peer side uses, and it works on any http.Handler.

Types

type Broker added in v0.37.0

type Broker struct {
	// contains filtered or unexported fields
}

Broker fans one Hook out to many watchers: the hub publishes each request once, and every console tab watching gets it.

Nothing is persisted. The broker keeps the last Recent events in memory so a tab that opens mid-traffic is not blank, and that buffer dies with the process. A watcher that falls behind loses events rather than slowing the request that produced them.

broker := reqlog.NewBroker(0)
proxy := revproxy.New(reg, revproxy.WithRequestHook(broker.Hook()))

for ev := range broker.Watch(ctx) { ... }

func NewBroker added in v0.37.0

func NewBroker(recent int) *Broker

NewBroker returns a broker replaying the last recent events to each new watcher. Pass 0 for DefaultRecent, or a negative number for no replay at all (a watcher then sees only what arrives after it).

func (*Broker) Hook added in v0.37.0

func (b *Broker) Hook() Hook

Hook returns the Hook that feeds the broker, for revproxy.WithRequestHook or dial.Options.RequestHook.

func (*Broker) Publish added in v0.37.0

func (b *Broker) Publish(ev Event)

Publish records an event and hands it to every watcher.

func (*Broker) Watch added in v0.37.0

func (b *Broker) Watch(ctx context.Context) <-chan Event

Watch streams events until ctx ends, starting with the recent ones the broker still holds (oldest first). The channel is closed when ctx does.

type Event

type Event struct {
	// At is when the response completed.
	At time.Time
	// Peer is the tunnel the request went through. The hub fills it;
	// a peer reporting its own requests leaves it empty, since it
	// knows only one.
	Peer string
	// Method and Path are the request's, as received.
	Method string
	Path   string
	// Status is the response code, 0 when the request never got one
	// (the connection died first).
	Status int
	// Duration is how long the response took at the reporting end,
	// so the hub's includes the tunnel hop and the peer's does not.
	Duration time.Duration
}

Event is one request, seen from whichever end reports it.

type Hook

type Hook func(Event)

Hook receives one event per request. It runs on the request's goroutine after the response, so it should not block: print, count, or hand off to a channel.

type Recorder

type Recorder struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Recorder captures the status code of a response while forwarding everything else, so a handler behind it keeps streaming, flushing and hijacking as it would without one.

func NewRecorder

func NewRecorder(w http.ResponseWriter) *Recorder

NewRecorder wraps w. Until the handler writes, the status reads as 200, which is what net/http sends for a handler that writes a body without calling WriteHeader.

func (*Recorder) Flush

func (r *Recorder) Flush()

Flush keeps streaming responses streaming: without it the wrapper would hide the underlying Flusher and the proxy's immediate flush would buffer.

func (*Recorder) Status

func (r *Recorder) Status() int

Status is the code the handler sent.

func (*Recorder) Unwrap

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

Unwrap lets http.ResponseController reach the real writer, which the standard library looks for (hijack, deadlines).

func (*Recorder) Write

func (r *Recorder) Write(b []byte) (int, error)

func (*Recorder) WriteHeader

func (r *Recorder) WriteHeader(code int)

Jump to

Keyboard shortcuts

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