From a58eecd436ff9344cda18efcdfa1da034503512e Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 8 Oct 2013 13:40:52 -0700 Subject: [PATCH 1/3] WinHTTP: set Accept header for POSTs --- src/transports/winhttp.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 067d6fcc3..95c9d10bb 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -265,8 +265,8 @@ static int winhttp_stream_connect(winhttp_stream *s) goto on_error; } - /* Send Content-Type header -- only necessary on a POST */ if (post_verb == s->verb) { + /* Send Content-Type header -- only necessary on a POST */ git_buf_clear(&buf); if (git_buf_printf(&buf, "Content-Type: application/x-git-%s-request", s->service) < 0) goto on_error; @@ -277,6 +277,16 @@ static int winhttp_stream_connect(winhttp_stream *s) giterr_set(GITERR_OS, "Failed to add a header to the request"); goto on_error; } + + /* Set the Accept header */ + git_buf_clear(&buf); + if (git_buf_printf(&buf, "Accept: application/x-git-%s-result\r\n", s->service) < 0) + goto on_error; + git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)); + if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_REPLACE)) { + giterr_set(GITERR_OS, "Failed to add a header to the request"); + goto on_error; + } } /* If requested, disable certificate validation */ From 1fd21b0342f4fc5ad38a74242385c202b272da80 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 8 Oct 2013 13:59:43 -0700 Subject: [PATCH 2/3] Add Assembla unit test --- tests-clar/online/clone.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c index 4a6ade52d..aa3d6b26a 100644 --- a/tests-clar/online/clone.c +++ b/tests-clar/online/clone.c @@ -11,6 +11,7 @@ #define BB_REPO_URL "https://libgit2@bitbucket.org/libgit2/testgitrepository.git" #define BB_REPO_URL_WITH_PASS "https://libgit2:libgit2@bitbucket.org/libgit2/testgitrepository.git" #define BB_REPO_URL_WITH_WRONG_PASS "https://libgit2:wrong@bitbucket.org/libgit2/testgitrepository.git" +#define ASSEMBLA_REPO_URL "https://libgit2:_Libgit2@git.assembla.com/libgit2-test-repos.git" static git_repository *g_repo; static git_clone_options g_options; @@ -227,6 +228,11 @@ void test_online_clone__bitbucket_style(void) cl_fixture_cleanup("./foo"); } +void test_online_clone__assembla_style(void) +{ + cl_git_pass(git_clone(&g_repo, ASSEMBLA_REPO_URL, "./foo", NULL)); +} + static int cancel_at_half(const git_transfer_progress *stats, void *payload) { GIT_UNUSED(payload); From 3dc3c723dac9fd2550530675b61849f2215ef767 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 8 Oct 2013 15:52:37 -0700 Subject: [PATCH 3/3] Combine WinHTTP API calls --- src/transports/winhttp.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 95c9d10bb..702243513 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -266,24 +266,18 @@ static int winhttp_stream_connect(winhttp_stream *s) } if (post_verb == s->verb) { - /* Send Content-Type header -- only necessary on a POST */ + /* Send Content-Type and Accept headers -- only necessary on a POST */ git_buf_clear(&buf); - if (git_buf_printf(&buf, "Content-Type: application/x-git-%s-request", s->service) < 0) + if (git_buf_printf(&buf, + "Content-Type: application/x-git-%s-request\r\n" + "Accept: application/x-git-%s-result\r\n", + s->service, s->service) < 0) goto on_error; git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)); - if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_ADD)) { - giterr_set(GITERR_OS, "Failed to add a header to the request"); - goto on_error; - } - - /* Set the Accept header */ - git_buf_clear(&buf); - if (git_buf_printf(&buf, "Accept: application/x-git-%s-result\r\n", s->service) < 0) - goto on_error; - git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)); - if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_REPLACE)) { + if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG) -1L, + WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { giterr_set(GITERR_OS, "Failed to add a header to the request"); goto on_error; }