Minor cleanup of _ostree_repo_remote_new_fetcher()

Instead of open coding the extra_headers and append_user_agent
setting everywhere we do this in the constructor.
This commit is contained in:
Alexander Larsson 2020-09-10 11:34:31 +02:00
parent 3957bff0cb
commit 155b215cd8
1 changed files with 12 additions and 14 deletions

View File

@ -2824,6 +2824,8 @@ static OstreeFetcher *
_ostree_repo_remote_new_fetcher (OstreeRepo *self, _ostree_repo_remote_new_fetcher (OstreeRepo *self,
const char *remote_name, const char *remote_name,
gboolean gzip, gboolean gzip,
GVariant *extra_headers,
const char *append_user_agent,
OstreeFetcherSecurityState *out_state, OstreeFetcherSecurityState *out_state,
GError **error) GError **error)
{ {
@ -2937,6 +2939,12 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self,
_ostree_fetcher_set_cookie_jar (fetcher, jar_path); _ostree_fetcher_set_cookie_jar (fetcher, jar_path);
} }
if (extra_headers)
_ostree_fetcher_set_extra_headers (fetcher, extra_headers);
if (append_user_agent)
_ostree_fetcher_set_extra_user_agent (fetcher, append_user_agent);
success = TRUE; success = TRUE;
out: out:
@ -3092,17 +3100,13 @@ reinitialize_fetcher (OtPullData *pull_data, const char *remote_name,
{ {
g_clear_object (&pull_data->fetcher); g_clear_object (&pull_data->fetcher);
pull_data->fetcher = _ostree_repo_remote_new_fetcher (pull_data->repo, remote_name, FALSE, pull_data->fetcher = _ostree_repo_remote_new_fetcher (pull_data->repo, remote_name, FALSE,
pull_data->extra_headers,
pull_data->append_user_agent,
&pull_data->fetcher_security_state, &pull_data->fetcher_security_state,
error); error);
if (pull_data->fetcher == NULL) if (pull_data->fetcher == NULL)
return FALSE; return FALSE;
if (pull_data->extra_headers)
_ostree_fetcher_set_extra_headers (pull_data->fetcher, pull_data->extra_headers);
if (pull_data->append_user_agent)
_ostree_fetcher_set_extra_user_agent (pull_data->fetcher, pull_data->append_user_agent);
return TRUE; return TRUE;
} }
@ -5454,7 +5458,7 @@ find_remotes_cb (GObject *obj,
goto error; goto error;
fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name, fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name,
TRUE, NULL, &error); TRUE, NULL, NULL, NULL, &error);
if (fetcher == NULL) if (fetcher == NULL)
goto error; goto error;
@ -6110,16 +6114,10 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self,
mainctx = _ostree_main_context_new_default (); mainctx = _ostree_main_context_new_default ();
fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, NULL, error); fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, NULL, error);
if (fetcher == NULL) if (fetcher == NULL)
return FALSE; return FALSE;
if (extra_headers)
_ostree_fetcher_set_extra_headers (fetcher, extra_headers);
if (append_user_agent)
_ostree_fetcher_set_extra_user_agent (fetcher, append_user_agent);
{ {
g_autofree char *url_string = NULL; g_autofree char *url_string = NULL;
if (metalink_url_string) if (metalink_url_string)