зеркало из https://github.com/microsoft/git.git
Merge branch 'jk/maint-http-half-auth-fetch'
Fixes fetch from servers that ask for auth only during the actual packing phase. This is not really a recommended configuration, but it cleans up the code at the same time. * jk/maint-http-half-auth-fetch: remote-curl: retry failed requests for auth even with gzip remote-curl: hoist gzip buffer size to top of post_rpc
This commit is contained in:
Коммит
a9bb4e55a3
|
@ -400,6 +400,7 @@ static int post_rpc(struct rpc_state *rpc)
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
int use_gzip = rpc->gzip_request;
|
int use_gzip = rpc->gzip_request;
|
||||||
char *gzip_body = NULL;
|
char *gzip_body = NULL;
|
||||||
|
size_t gzip_size;
|
||||||
int err, large_request = 0;
|
int err, large_request = 0;
|
||||||
|
|
||||||
/* Try to load the entire request, if we can fit it into the
|
/* Try to load the entire request, if we can fit it into the
|
||||||
|
@ -460,24 +461,32 @@ retry:
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (gzip_body) {
|
||||||
|
/*
|
||||||
|
* If we are looping to retry authentication, then the previous
|
||||||
|
* run will have set up the headers and gzip buffer already,
|
||||||
|
* and we just need to send it.
|
||||||
|
*/
|
||||||
|
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
|
||||||
|
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
|
||||||
|
|
||||||
} else if (use_gzip && 1024 < rpc->len) {
|
} else if (use_gzip && 1024 < rpc->len) {
|
||||||
/* The client backend isn't giving us compressed data so
|
/* The client backend isn't giving us compressed data so
|
||||||
* we can try to deflate it ourselves, this may save on.
|
* we can try to deflate it ourselves, this may save on.
|
||||||
* the transfer time.
|
* the transfer time.
|
||||||
*/
|
*/
|
||||||
size_t size;
|
|
||||||
git_zstream stream;
|
git_zstream stream;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
memset(&stream, 0, sizeof(stream));
|
memset(&stream, 0, sizeof(stream));
|
||||||
git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
|
git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
|
||||||
size = git_deflate_bound(&stream, rpc->len);
|
gzip_size = git_deflate_bound(&stream, rpc->len);
|
||||||
gzip_body = xmalloc(size);
|
gzip_body = xmalloc(gzip_size);
|
||||||
|
|
||||||
stream.next_in = (unsigned char *)rpc->buf;
|
stream.next_in = (unsigned char *)rpc->buf;
|
||||||
stream.avail_in = rpc->len;
|
stream.avail_in = rpc->len;
|
||||||
stream.next_out = (unsigned char *)gzip_body;
|
stream.next_out = (unsigned char *)gzip_body;
|
||||||
stream.avail_out = size;
|
stream.avail_out = gzip_size;
|
||||||
|
|
||||||
ret = git_deflate(&stream, Z_FINISH);
|
ret = git_deflate(&stream, Z_FINISH);
|
||||||
if (ret != Z_STREAM_END)
|
if (ret != Z_STREAM_END)
|
||||||
|
@ -487,16 +496,16 @@ retry:
|
||||||
if (ret != Z_OK)
|
if (ret != Z_OK)
|
||||||
die("cannot deflate request; zlib end error %d", ret);
|
die("cannot deflate request; zlib end error %d", ret);
|
||||||
|
|
||||||
size = stream.total_out;
|
gzip_size = stream.total_out;
|
||||||
|
|
||||||
headers = curl_slist_append(headers, "Content-Encoding: gzip");
|
headers = curl_slist_append(headers, "Content-Encoding: gzip");
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
|
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, size);
|
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
|
||||||
|
|
||||||
if (options.verbosity > 1) {
|
if (options.verbosity > 1) {
|
||||||
fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
|
fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
|
||||||
rpc->service_name,
|
rpc->service_name,
|
||||||
(unsigned long)rpc->len, (unsigned long)size);
|
(unsigned long)rpc->len, (unsigned long)gzip_size);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -517,7 +526,7 @@ retry:
|
||||||
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
|
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
|
||||||
|
|
||||||
err = run_slot(slot);
|
err = run_slot(slot);
|
||||||
if (err == HTTP_REAUTH && !large_request && !use_gzip)
|
if (err == HTTP_REAUTH && !large_request)
|
||||||
goto retry;
|
goto retry;
|
||||||
if (err != HTTP_OK)
|
if (err != HTTP_OK)
|
||||||
err = -1;
|
err = -1;
|
||||||
|
|
|
@ -99,6 +99,13 @@ SSLEngine On
|
||||||
Require valid-user
|
Require valid-user
|
||||||
</LocationMatch>
|
</LocationMatch>
|
||||||
|
|
||||||
|
<LocationMatch "^/auth-fetch/.*/git-upload-pack$">
|
||||||
|
AuthType Basic
|
||||||
|
AuthName "git-auth"
|
||||||
|
AuthUserFile passwd
|
||||||
|
Require valid-user
|
||||||
|
</LocationMatch>
|
||||||
|
|
||||||
<IfDefine DAV>
|
<IfDefine DAV>
|
||||||
LoadModule dav_module modules/mod_dav.so
|
LoadModule dav_module modules/mod_dav.so
|
||||||
LoadModule dav_fs_module modules/mod_dav_fs.so
|
LoadModule dav_fs_module modules/mod_dav_fs.so
|
||||||
|
|
|
@ -130,6 +130,21 @@ test_expect_success 'clone from auth-only-for-push repository' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone from auth-only-for-objects repository' '
|
||||||
|
echo two >expect &&
|
||||||
|
set_askpass user@host &&
|
||||||
|
git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
|
||||||
|
expect_askpass both user@host &&
|
||||||
|
git --git-dir=half-auth log -1 --format=%s >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'no-op half-auth fetch does not require a password' '
|
||||||
|
set_askpass wrong &&
|
||||||
|
git --git-dir=half-auth fetch &&
|
||||||
|
expect_askpass none
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'disable dumb http on server' '
|
test_expect_success 'disable dumb http on server' '
|
||||||
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
||||||
config http.getanyfile false
|
config http.getanyfile false
|
||||||
|
|
Загрузка…
Ссылка в новой задаче