Unverified Commit 53a8f463 by Patrick Steinhardt Committed by GitHub

Merge pull request #5536 from libgit2/ethomson/http

httpclient: support googlesource
parents 6de8aa7f 04c7bdb4
...@@ -1038,6 +1038,7 @@ on_error: ...@@ -1038,6 +1038,7 @@ on_error:
GIT_INLINE(int) client_read(git_http_client *client) GIT_INLINE(int) client_read(git_http_client *client)
{ {
http_parser_context *parser_context = client->parser.data;
git_stream *stream; git_stream *stream;
char *buf = client->read_buf.ptr + client->read_buf.size; char *buf = client->read_buf.ptr + client->read_buf.size;
size_t max_len; size_t max_len;
...@@ -1054,6 +1055,9 @@ GIT_INLINE(int) client_read(git_http_client *client) ...@@ -1054,6 +1055,9 @@ GIT_INLINE(int) client_read(git_http_client *client)
max_len = client->read_buf.asize - client->read_buf.size; max_len = client->read_buf.asize - client->read_buf.size;
max_len = min(max_len, INT_MAX); max_len = min(max_len, INT_MAX);
if (parser_context->output_size)
max_len = min(max_len, parser_context->output_size);
if (max_len == 0) { if (max_len == 0) {
git_error_set(GIT_ERROR_HTTP, "no room in output buffer"); git_error_set(GIT_ERROR_HTTP, "no room in output buffer");
return -1; return -1;
...@@ -1191,7 +1195,7 @@ static void complete_response_body(git_http_client *client) ...@@ -1191,7 +1195,7 @@ static void complete_response_body(git_http_client *client)
/* If we're not keeping alive, don't bother. */ /* If we're not keeping alive, don't bother. */
if (!client->keepalive) { if (!client->keepalive) {
client->connected = 0; client->connected = 0;
return; goto done;
} }
parser_context.client = client; parser_context.client = client;
...@@ -1205,6 +1209,9 @@ static void complete_response_body(git_http_client *client) ...@@ -1205,6 +1209,9 @@ static void complete_response_body(git_http_client *client)
git_error_clear(); git_error_clear();
client->connected = 0; client->connected = 0;
} }
done:
git_buf_clear(&client->read_buf);
} }
int git_http_client_send_request( int git_http_client_send_request(
...@@ -1419,15 +1426,20 @@ int git_http_client_read_body( ...@@ -1419,15 +1426,20 @@ int git_http_client_read_body(
client->parser.data = &parser_context; client->parser.data = &parser_context;
/* /*
* Clients expect to get a non-zero amount of data from us. * Clients expect to get a non-zero amount of data from us,
* With a sufficiently small buffer, one might only read a chunk * so we either block until we have data to return, until we
* length. Loop until we actually have data to return. * hit EOF or there's an error. Do this in a loop, since we
* may end up reading only some stream metadata (like chunk
* information).
*/ */
while (!parser_context.output_written) { while (!parser_context.output_written) {
error = client_read_and_parse(client); error = client_read_and_parse(client);
if (error <= 0) if (error <= 0)
goto done; goto done;
if (client->state == DONE)
break;
} }
assert(parser_context.output_written <= INT_MAX); assert(parser_context.output_written <= INT_MAX);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define BB_REPO_URL "https://libgit3@bitbucket.org/libgit2/testgitrepository.git" #define BB_REPO_URL "https://libgit3@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_PASS "https://libgit3:libgit3@bitbucket.org/libgit2/testgitrepository.git" #define BB_REPO_URL_WITH_PASS "https://libgit3:libgit3@bitbucket.org/libgit2/testgitrepository.git"
#define BB_REPO_URL_WITH_WRONG_PASS "https://libgit3:wrong@bitbucket.org/libgit2/testgitrepository.git" #define BB_REPO_URL_WITH_WRONG_PASS "https://libgit3:wrong@bitbucket.org/libgit2/testgitrepository.git"
#define GOOGLESOURCE_REPO_URL "https://chromium.googlesource.com/external/github.com/sergi/go-diff"
#define SSH_REPO_URL "ssh://github.com/libgit2/TestGitRepository" #define SSH_REPO_URL "ssh://github.com/libgit2/TestGitRepository"
...@@ -463,6 +464,13 @@ void test_online_clone__bitbucket_falls_back_to_specified_creds(void) ...@@ -463,6 +464,13 @@ void test_online_clone__bitbucket_falls_back_to_specified_creds(void)
cl_fixture_cleanup("./foo"); cl_fixture_cleanup("./foo");
} }
void test_online_clone__googlesource(void)
{
cl_git_pass(git_clone(&g_repo, GOOGLESOURCE_REPO_URL, "./foo", &g_options));
git_repository_free(g_repo); g_repo = NULL;
cl_fixture_cleanup("./foo");
}
static int cancel_at_half(const git_indexer_progress *stats, void *payload) static int cancel_at_half(const git_indexer_progress *stats, void *payload)
{ {
GIT_UNUSED(payload); GIT_UNUSED(payload);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment