Skip to content

Commit

Permalink
client: Retry when told to by the proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Jul 20, 2024
1 parent 7cd606c commit 173e64c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion client/incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,21 @@ func (r *ProtocolIncus) DoHTTP(req *http.Request) (*http.Response, error) {
return r.oidcClient.do(req)
}

return r.http.Do(req)
resp, err := r.http.Do(req)
if resp != nil && resp.StatusCode == http.StatusUseProxy && req.GetBody != nil {
// Reset the request body.
body, err := req.GetBody()
if err != nil {
return nil, err
}

req.Body = body

// Retry the request.
return r.http.Do(req)
}

return resp, err
}

// DoWebsocket performs a websocket connection, using OIDC authentication if set.
Expand Down

0 comments on commit 173e64c

Please sign in to comment.