Skip to content

Commit 8c7345e

Browse files
authored
Merge pull request libgit2#6416 from slackner/httpclient_update_options
http: Update httpclient options when reusing an existing connection.
2 parents a7d841a + f8683b7 commit 8c7345e

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/libgit2/transports/http.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ static int http_action(
655655
{
656656
http_subtransport *transport = GIT_CONTAINER_OF(t, http_subtransport, parent);
657657
git_remote_connect_options *connect_opts = &transport->owner->connect_opts;
658+
git_http_client_options opts = {0};
658659
http_stream *stream;
659660
const http_service *service;
660661
int error;
@@ -683,14 +684,14 @@ static int http_action(
683684
stream = git__calloc(sizeof(http_stream), 1);
684685
GIT_ERROR_CHECK_ALLOC(stream);
685686

686-
if (!transport->http_client) {
687-
git_http_client_options opts = {0};
688-
689-
opts.server_certificate_check_cb = connect_opts->callbacks.certificate_check;
690-
opts.server_certificate_check_payload = connect_opts->callbacks.payload;
691-
opts.proxy_certificate_check_cb = connect_opts->proxy_opts.certificate_check;
692-
opts.proxy_certificate_check_payload = connect_opts->proxy_opts.payload;
687+
opts.server_certificate_check_cb = connect_opts->callbacks.certificate_check;
688+
opts.server_certificate_check_payload = connect_opts->callbacks.payload;
689+
opts.proxy_certificate_check_cb = connect_opts->proxy_opts.certificate_check;
690+
opts.proxy_certificate_check_payload = connect_opts->proxy_opts.payload;
693691

692+
if (transport->http_client) {
693+
git_http_client_set_options(transport->http_client, &opts);
694+
} else {
694695
if (git_http_client_new(&transport->http_client, &opts) < 0)
695696
return -1;
696697
}

src/libgit2/transports/httpclient.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,15 @@ int git_http_client_new(
15411541
return 0;
15421542
}
15431543

1544+
/* Update the options of an existing httpclient instance. */
1545+
void git_http_client_set_options(
1546+
git_http_client *client,
1547+
git_http_client_options *opts)
1548+
{
1549+
if (opts)
1550+
memcpy(&client->opts, opts, sizeof(git_http_client_options));
1551+
}
1552+
15441553
GIT_INLINE(void) http_server_close(git_http_server *server)
15451554
{
15461555
if (server->stream) {

src/libgit2/transports/httpclient.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ extern int git_http_client_new(
8888
git_http_client **out,
8989
git_http_client_options *opts);
9090

91+
/**
92+
* Update the options of an existing httpclient instance.
93+
*
94+
* @param client the httpclient instance to modify
95+
* @param opts new options or NULL to keep existing options
96+
*/
97+
extern void git_http_client_set_options(
98+
git_http_client *client,
99+
git_http_client_options *opts);
100+
91101
/*
92102
* Sends a request to the host specified by the request URL. If the
93103
* method is POST, either the content_length or the chunked flag must

0 commit comments

Comments
 (0)