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:
parent
24bc95e1d8
commit
4ed54bc359
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue