summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-06-16 16:32:15 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-06-16 16:32:15 -0700
commit356169c1f66287629ea08e8c9c6e27b00ff8707a (patch)
treedbcaccfc020329501fb6eaa9c84c06e5d4ab7bf6 /http.c
parentMerge branch 'by/blame-doc-m-c' into maint (diff)
parentPrompt for a username when an HTTP request 401s (diff)
downloadtgif-356169c1f66287629ea08e8c9c6e27b00ff8707a.tar.xz
Merge branch 'sc/http-late-auth' into maint
* sc/http-late-auth: Prompt for a username when an HTTP request 401s
Diffstat (limited to 'http.c')
-rw-r--r--http.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/http.c b/http.c
index 901e597297..1320c50e32 100644
--- a/http.c
+++ b/http.c
@@ -816,7 +816,21 @@ static int http_request(const char *url, void *result, int target, int options)
ret = HTTP_OK;
else if (missing_target(&results))
ret = HTTP_MISSING_TARGET;
- else
+ else if (results.http_code == 401) {
+ if (user_name) {
+ ret = HTTP_NOAUTH;
+ } else {
+ /*
+ * git_getpass is needed here because its very likely stdin/stdout are
+ * pipes to our parent process. So we instead need to use /dev/tty,
+ * but that is non-portable. Using git_getpass() can at least be stubbed
+ * on other platforms with a different implementation if/when necessary.
+ */
+ user_name = xstrdup(git_getpass("Username: "));
+ init_curl_http_auth(slot->curl);
+ ret = HTTP_REAUTH;
+ }
+ } else
ret = HTTP_ERROR;
} else {
error("Unable to start HTTP request for %s", url);
@@ -832,7 +846,11 @@ static int http_request(const char *url, void *result, int target, int options)
int http_get_strbuf(const char *url, struct strbuf *result, int options)
{
- return http_request(url, result, HTTP_REQUEST_STRBUF, options);
+ int http_ret = http_request(url, result, HTTP_REQUEST_STRBUF, options);
+ if (http_ret == HTTP_REAUTH) {
+ http_ret = http_request(url, result, HTTP_REQUEST_STRBUF, options);
+ }
+ return http_ret;
}
/*