From cf0633af7c6766ce72d238b5a65fd143d2b30002 Mon Sep 17 00:00:00 2001 From: Jason Chu Date: Fri, 5 Jan 2024 21:08:24 +0000 Subject: [PATCH] add stupid workaround --- mini.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mini.go b/mini.go index 57a2cc4..3f1251f 100644 --- a/mini.go +++ b/mini.go @@ -34,6 +34,17 @@ type RemoteConfig struct { Secret []byte } +// the registry and TransportWorkaround are used to work around a bug in yaegi. +var transportRegistry = make(map[string]func(req *http.Request) (*http.Response, error)) + +type TransportWorkaround struct { + configID string +} + +func (t TransportWorkaround) RoundTrip(req *http.Request) (*http.Response, error) { + return transportRegistry[t.configID](req) +} + func NewMini(config MiniConfig, next CaddyHandleFunc) (*Tmpauth, error) { var lastErr error var remoteConfig RemoteConfig @@ -123,11 +134,13 @@ func NewMini(config MiniConfig, next CaddyHandleFunc) (*Tmpauth, error) { tmpauth: t, } + transportRegistry[remoteConfig.ConfigID] = transport.RoundTrip + t.miniClient = &http.Client{ CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, - Transport: MakeRoundTripper(transport), + Transport: TransportWorkaround{configID: remoteConfig.ConfigID}, } return t, nil @@ -156,10 +169,6 @@ func (t *Tmpauth) ReauthMini() error { return nil } -func MakeRoundTripper(v interface{}) http.RoundTripper { - return v.(http.RoundTripper) -} - type MiniTransport struct { base http.RoundTripper tmpauth *Tmpauth