Skip to content

Commit 4ed54bc

Browse files
Paulo Gomesdarkowlzz
authored andcommitted
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 <[email protected]>
1 parent 24bc95e commit 4ed54bc

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

pkg/git/libgit2/managed/http.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,15 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
288288
if err.Error() != git2go.ErrorCodePassthrough.String() {
289289
return err
290290
}
291-
} else {
291+
}
292+
293+
if cred != nil {
294+
defer cred.Free()
295+
292296
userName, password, err = cred.GetUserpassPlaintext()
293297
if err != nil {
294298
return err
295299
}
296-
defer cred.Free()
297300
}
298301

299302
for {
@@ -317,23 +320,6 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
317320
break
318321
}
319322

320-
if resp.StatusCode == http.StatusUnauthorized {
321-
resp.Body.Close()
322-
323-
cred, err := self.owner.transport.SmartCredentials("", git2go.CredentialTypeUserpassPlaintext)
324-
if err != nil {
325-
return err
326-
}
327-
defer cred.Free()
328-
329-
userName, password, err = cred.GetUserpassPlaintext()
330-
if err != nil {
331-
return err
332-
}
333-
334-
continue
335-
}
336-
337323
io.Copy(ioutil.Discard, resp.Body)
338324
resp.Body.Close()
339325
return fmt.Errorf("Unhandled HTTP error %s", resp.Status)

0 commit comments

Comments
 (0)