Skip to content

Commit 46228d8

Browse files
committed
transports: http: fix custom headers not being applied
In commit b9c5b15 (http: use the new httpclient, 2019-12-22), the HTTP code got refactored to extract a generic HTTP client that operates independently of the Git protocol. Part of refactoring was the creation of a new `git_http_request` struct that encapsulates the generation of requests. Our Git-specific HTTP transport was converted to use that in `generate_request`, but during the process we forgot to set up custom headers for the `git_http_request` and as a result we do not send out these headers anymore. Fix the issue by correctly setting up the request's custom headers and add a test to verify we correctly send them.
1 parent bd6b1c4 commit 46228d8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/transports/http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ static int generate_request(
346346
request->credentials = transport->server.cred;
347347
request->proxy = use_proxy ? &transport->proxy.url : NULL;
348348
request->proxy_credentials = transport->proxy.cred;
349+
request->custom_headers = &transport->owner->custom_headers;
349350

350351
if (stream->service->method == GIT_HTTP_METHOD_POST) {
351352
request->chunked = stream->service->chunked;

tests/online/clone.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,21 @@ void test_online_clone__credentials(void)
392392
cl_fixture_cleanup("./foo");
393393
}
394394

395+
void test_online_clone__credentials_via_custom_headers(void)
396+
{
397+
const char *creds = "libgit3:libgit3";
398+
git_buf auth = GIT_BUF_INIT;
399+
400+
cl_git_pass(git_buf_puts(&auth, "Authorization: Basic "));
401+
cl_git_pass(git_buf_encode_base64(&auth, creds, strlen(creds)));
402+
g_options.fetch_opts.custom_headers.count = 1;
403+
g_options.fetch_opts.custom_headers.strings = &auth.ptr;
404+
405+
cl_git_pass(git_clone(&g_repo, "https://bitbucket.org/libgit2/testgitrepository.git", "./foo", &g_options));
406+
407+
git_buf_dispose(&auth);
408+
}
409+
395410
void test_online_clone__bitbucket_style(void)
396411
{
397412
git_credential_userpass_payload user_pass = {

0 commit comments

Comments
 (0)