Optimise basic auth for libgit2 managed transport

The initial implementation was based off upstream, which cause
an initial request to fail, and only then the credentials would
be added into the request.

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
This commit is contained in:
Paulo Gomes 2022-03-14 17:46:55 +00:00 committed by Sunny
parent 24bc95e1d8
commit 4ed54bc359
No known key found for this signature in database
GPG Key ID: 9F3D25DDFF7FA3CF
1 changed files with 5 additions and 19 deletions

View File

@ -288,12 +288,15 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
if err.Error() != git2go.ErrorCodePassthrough.String() {
return err
}
} else {
}
if cred != nil {
defer cred.Free()
userName, password, err = cred.GetUserpassPlaintext()
if err != nil {
return err
}
defer cred.Free()
}
for {
@ -317,23 +320,6 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
break
}
if resp.StatusCode == http.StatusUnauthorized {
resp.Body.Close()
cred, err := self.owner.transport.SmartCredentials("", git2go.CredentialTypeUserpassPlaintext)
if err != nil {
return err
}
defer cred.Free()
userName, password, err = cred.GetUserpassPlaintext()
if err != nil {
return err
}
continue
}
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
return fmt.Errorf("Unhandled HTTP error %s", resp.Status)