Skip to content

Commit

Permalink
stupid yaegi workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
1lann committed Jan 5, 2024
1 parent decc88e commit 817680a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions mini.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func NewMini(config MiniConfig, next CaddyHandleFunc) (*Tmpauth, error) {
}

transport := &MiniTransport{
RoundTripper: http.DefaultTransport,
tmpauth: t,
base: http.DefaultTransport,
tmpauth: t,
}

t.miniClient = &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
Transport: PromiseRoundTripper{transport.RoundTrip},
Transport: MakeRoundTripper(transport),
}

return t, nil
Expand Down Expand Up @@ -156,16 +156,12 @@ func (t *Tmpauth) ReauthMini() error {
return nil
}

type PromiseRoundTripper struct {
roundTrip func(*http.Request) (*http.Response, error)
}

func (p PromiseRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
return p.RoundTrip(req)
func MakeRoundTripper(v interface{}) http.RoundTripper {
return v.(http.RoundTripper)
}

type MiniTransport struct {
http.RoundTripper
base http.RoundTripper
tmpauth *Tmpauth
}

Expand All @@ -189,7 +185,7 @@ func (t *MiniTransport) RoundTrip(req *http.Request) (*http.Response, error) {

req.Body = io.NopCloser(bytes.NewReader(body))

resp, err := t.RoundTripper.RoundTrip(req)
resp, err := t.base.RoundTrip(req)
if resp.StatusCode == http.StatusPreconditionFailed {
// our config ID is wrong
err := t.tmpauth.ReauthMini()
Expand Down

0 comments on commit 817680a

Please sign in to comment.