diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2021-12-24 15:14:38 -0600 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-06 15:18:33 -0500 |
commit | 6fc6eeb66c40310086c8f059cae41de69ad4c6da (patch) | |
tree | 0c5453c41d0886abb5eb35faeb2a0d180da91a6d /src/transports/http.c | |
parent | f99a0d695c0a1a8e44fc1e5216d481ff016ec65d (diff) | |
download | libgit2-6fc6eeb66c40310086c8f059cae41de69ad4c6da.tar.gz |
remote: introduce `git_remote_connect_options`ethomson/remote_connect_opts
The existing mechanism for providing options to remote fetch/push calls,
and subsequently to transports, is unsatisfactory. It requires an
options structure to avoid breaking the API and callback signatures.
1. Introduce `git_remote_connect_options` to satisfy those needs.
2. Add a new remote connection API, `git_remote_connect_ext` that will
take this new options structure. Existing `git_remote_connect` calls
will proxy to that. `git_remote_fetch` and `git_remote_push` will
proxy their fetch/push options to that as well.
3. Define the interaction between `git_remote_connect` and fetch/push.
Connect _may_ be called before fetch/push, but _need not_ be. The
semantics of which options would be used for these operations was
not specified if you specify options for both connect _and_ fetch.
Now these are defined that the fetch or push options will be used
_if_ they were specified. Otherwise, the connect options will be
used if they were specified. Otherwise, the library's defaults will
be used.
4. Update the transports to understand `git_remote_connect_options`.
This is a breaking change to the systems API.
Diffstat (limited to 'src/transports/http.c')
-rw-r--r-- | src/transports/http.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/transports/http.c b/src/transports/http.c index adcb1ac43..fa576ff3e 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -174,6 +174,7 @@ GIT_INLINE(int) handle_remote_auth( git_http_response *response) { http_subtransport *transport = OWNING_SUBTRANSPORT(stream); + git_remote_connect_options *connect_opts = &transport->owner->connect_opts; if (response->server_auth_credtypes == 0) { git_error_set(GIT_ERROR_HTTP, "server requires authentication that we do not support"); @@ -187,8 +188,8 @@ GIT_INLINE(int) handle_remote_auth( transport->owner->url, response->server_auth_schemetypes, response->server_auth_credtypes, - transport->owner->cred_acquire_cb, - transport->owner->cred_acquire_payload); + connect_opts->callbacks.credentials, + connect_opts->callbacks.payload); } GIT_INLINE(int) handle_proxy_auth( @@ -196,6 +197,7 @@ GIT_INLINE(int) handle_proxy_auth( git_http_response *response) { http_subtransport *transport = OWNING_SUBTRANSPORT(stream); + git_remote_connect_options *connect_opts = &transport->owner->connect_opts; if (response->proxy_auth_credtypes == 0) { git_error_set(GIT_ERROR_HTTP, "proxy requires authentication that we do not support"); @@ -206,11 +208,11 @@ GIT_INLINE(int) handle_proxy_auth( return handle_auth( &transport->proxy, SERVER_TYPE_PROXY, - transport->owner->proxy.url, + connect_opts->proxy_opts.url, response->server_auth_schemetypes, response->proxy_auth_credtypes, - transport->owner->proxy.credentials, - transport->owner->proxy.payload); + connect_opts->proxy_opts.credentials, + connect_opts->proxy_opts.payload); } @@ -286,6 +288,7 @@ static int lookup_proxy( bool *out_use, http_subtransport *transport) { + git_remote_connect_options *connect_opts = &transport->owner->connect_opts; const char *proxy; git_remote *remote; char *config = NULL; @@ -294,9 +297,9 @@ static int lookup_proxy( *out_use = false; git_net_url_dispose(&transport->proxy.url); - switch (transport->owner->proxy.type) { + switch (connect_opts->proxy_opts.type) { case GIT_PROXY_SPECIFIED: - proxy = transport->owner->proxy.url; + proxy = connect_opts->proxy_opts.url; break; case GIT_PROXY_AUTO: @@ -345,7 +348,7 @@ static int generate_request( request->credentials = transport->server.cred; request->proxy = use_proxy ? &transport->proxy.url : NULL; request->proxy_credentials = transport->proxy.cred; - request->custom_headers = &transport->owner->custom_headers; + request->custom_headers = &transport->owner->connect_opts.custom_headers; if (stream->service->method == GIT_HTTP_METHOD_POST) { request->chunked = stream->service->chunked; @@ -633,6 +636,7 @@ static int http_action( git_smart_service_t action) { http_subtransport *transport = GIT_CONTAINER_OF(t, http_subtransport, parent); + git_remote_connect_options *connect_opts = &transport->owner->connect_opts; http_stream *stream; const http_service *service; int error; @@ -664,10 +668,10 @@ static int http_action( if (!transport->http_client) { git_http_client_options opts = {0}; - opts.server_certificate_check_cb = transport->owner->certificate_check_cb; - opts.server_certificate_check_payload = transport->owner->message_cb_payload; - opts.proxy_certificate_check_cb = transport->owner->proxy.certificate_check; - opts.proxy_certificate_check_payload = transport->owner->proxy.payload; + opts.server_certificate_check_cb = connect_opts->callbacks.certificate_check; + opts.server_certificate_check_payload = connect_opts->callbacks.payload; + opts.proxy_certificate_check_cb = connect_opts->proxy_opts.certificate_check; + opts.proxy_certificate_check_payload = connect_opts->proxy_opts.payload; if (git_http_client_new(&transport->http_client, &opts) < 0) return -1; |