Skip to content

Commit

Permalink
add stupid workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
1lann committed Jan 5, 2024
1 parent 817680a commit cf0633a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions mini.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf0633a

Please sign in to comment.