summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transports/http.c14
-rw-r--r--src/transports/winhttp.c5
2 files changed, 19 insertions, 0 deletions
diff --git a/src/transports/http.c b/src/transports/http.c
index 6c116d8e7..964bafb19 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -63,6 +63,7 @@ typedef struct {
char *user_from_url;
char *pass_from_url;
git_cred *cred;
+ git_cred *url_cred;
http_authmechanism_t auth_mechanism;
unsigned connected : 1,
use_ssl : 1;
@@ -146,6 +147,14 @@ static int gen_request(
apply_basic_credential(buf, t->cred) < 0)
return -1;
+ /* Use url-parsed basic auth if username and password are both provided */
+ if (!t->cred && t->user_from_url && t->pass_from_url) {
+ if (!t->url_cred &&
+ git_cred_userpass_plaintext_new(&t->url_cred, t->user_from_url, t->pass_from_url) < 0)
+ return -1;
+ if (apply_basic_credential(buf, t->url_cred) < 0) return -1;
+ }
+
git_buf_puts(buf, "\r\n");
if (git_buf_oom(buf))
@@ -812,6 +821,11 @@ static int http_close(git_smart_subtransport *subtransport)
t->cred = NULL;
}
+ if (t->url_cred) {
+ t->url_cred->free(t->url_cred);
+ t->url_cred = NULL;
+ }
+
if (t->host) {
git__free(t->host);
t->host = NULL;
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 4ac085ed3..780b84e45 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -960,6 +960,11 @@ static int winhttp_close(git_smart_subtransport *subtransport)
t->cred = NULL;
}
+ if (t->url_cred) {
+ t->url_cred->free(t->url_cred);
+ t->url_cred = NULL;
+ }
+
if (t->connection) {
if (!WinHttpCloseHandle(t->connection)) {
giterr_set(GITERR_OS, "Unable to close connection");