diff --git a/src/net/http/tailscale.go b/src/net/http/tailscale.go new file mode 100644 index 0000000000000..3e67c84661087 --- /dev/null +++ b/src/net/http/tailscale.go @@ -0,0 +1,13 @@ +package http + +var roundTripEnforcer func(*Request) error + +func SetRoundTripEnforcer(f func(*Request) error) { + if f == nil { + panic("nil func") + } + if roundTripEnforcer != nil { + panic("already called") + } + roundTripEnforcer = f +} diff --git a/src/net/http/transport.go b/src/net/http/transport.go index c07352b018e1e..4d9efe270840b 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -511,6 +511,11 @@ func (t *Transport) alternateRoundTripper(req *Request) RoundTripper { // roundTrip implements a RoundTripper over HTTP. func (t *Transport) roundTrip(req *Request) (*Response, error) { + if roundTripEnforcer != nil { + if err := roundTripEnforcer(req); err != nil { + return nil, err + } + } t.nextProtoOnce.Do(t.onceSetNextProtoDefaults) ctx := req.Context() trace := httptrace.ContextClientTrace(ctx)