Skip to content

Commit 53a8f46

Browse files
authored
Merge pull request libgit2#5536 from libgit2/ethomson/http
httpclient: support googlesource
2 parents 6de8aa7 + 04c7bdb commit 53a8f46

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/transports/httpclient.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,7 @@ static int http_client_connect(
10381038

10391039
GIT_INLINE(int) client_read(git_http_client *client)
10401040
{
1041+
http_parser_context *parser_context = client->parser.data;
10411042
git_stream *stream;
10421043
char *buf = client->read_buf.ptr + client->read_buf.size;
10431044
size_t max_len;
@@ -1054,6 +1055,9 @@ GIT_INLINE(int) client_read(git_http_client *client)
10541055
max_len = client->read_buf.asize - client->read_buf.size;
10551056
max_len = min(max_len, INT_MAX);
10561057

1058+
if (parser_context->output_size)
1059+
max_len = min(max_len, parser_context->output_size);
1060+
10571061
if (max_len == 0) {
10581062
git_error_set(GIT_ERROR_HTTP, "no room in output buffer");
10591063
return -1;
@@ -1191,7 +1195,7 @@ static void complete_response_body(git_http_client *client)
11911195
/* If we're not keeping alive, don't bother. */
11921196
if (!client->keepalive) {
11931197
client->connected = 0;
1194-
return;
1198+
goto done;
11951199
}
11961200

11971201
parser_context.client = client;
@@ -1205,6 +1209,9 @@ static void complete_response_body(git_http_client *client)
12051209
git_error_clear();
12061210
client->connected = 0;
12071211
}
1212+
1213+
done:
1214+
git_buf_clear(&client->read_buf);
12081215
}
12091216

12101217
int git_http_client_send_request(
@@ -1419,15 +1426,20 @@ int git_http_client_read_body(
14191426
client->parser.data = &parser_context;
14201427

14211428
/*
1422-
* Clients expect to get a non-zero amount of data from us.
1423-
* With a sufficiently small buffer, one might only read a chunk
1424-
* length. Loop until we actually have data to return.
1429+
* Clients expect to get a non-zero amount of data from us,
1430+
* so we either block until we have data to return, until we
1431+
* hit EOF or there's an error. Do this in a loop, since we
1432+
* may end up reading only some stream metadata (like chunk
1433+
* information).
14251434
*/
14261435
while (!parser_context.output_written) {
14271436
error = client_read_and_parse(client);
14281437

14291438
if (error <= 0)
14301439
goto done;
1440+
1441+
if (client->state == DONE)
1442+
break;
14311443
}
14321444

14331445
assert(parser_context.output_written <= INT_MAX);

tests/online/clone.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define BB_REPO_URL "https://libgit3@bitbucket.org/libgit2/testgitrepository.git"
1212
#define BB_REPO_URL_WITH_PASS "https://libgit3:libgit3@bitbucket.org/libgit2/testgitrepository.git"
1313
#define BB_REPO_URL_WITH_WRONG_PASS "https://libgit3:wrong@bitbucket.org/libgit2/testgitrepository.git"
14+
#define GOOGLESOURCE_REPO_URL "https://chromium.googlesource.com/external/github.com/sergi/go-diff"
1415

1516
#define SSH_REPO_URL "ssh://github.com/libgit2/TestGitRepository"
1617

@@ -463,6 +464,13 @@ void test_online_clone__bitbucket_falls_back_to_specified_creds(void)
463464
cl_fixture_cleanup("./foo");
464465
}
465466

467+
void test_online_clone__googlesource(void)
468+
{
469+
cl_git_pass(git_clone(&g_repo, GOOGLESOURCE_REPO_URL, "./foo", &g_options));
470+
git_repository_free(g_repo); g_repo = NULL;
471+
cl_fixture_cleanup("./foo");
472+
}
473+
466474
static int cancel_at_half(const git_indexer_progress *stats, void *payload)
467475
{
468476
GIT_UNUSED(payload);

0 commit comments

Comments
 (0)