pull: Add support for http-headers option
Some deployments may want to gate access to content based on things like OAuth. In this model, the client system would normally compute a token and pass it to the server via an API. We could theoretically support this in the remote config too, but that'd be a bit weird for OAuth as the information is dynamic. Therefore this cleans up the code a little bit to more clearly handle the case that the fetcher is initialized from both remote config data plus pull options. Closes: #574 Approved by: giuseppe
This commit is contained in:
1 parent
4b7ab5167c
commit
37c07d2f1c
7 files changed
+171
-6
No files matched your search
@@ -53,6 +53,7 @@ typedef struct {
|
||||
GLnxLockFile tmpdir_lock;
|
||||
int base_tmpdir_dfd;
|
||||
|
||||
GVariant *extra_headers;
|
||||
int max_outstanding;
|
||||
|
||||
/* Queue for libsoup, see bgo#708591 */
|
||||
@@ -148,6 +149,8 @@ thread_closure_unref (ThreadClosure *thread_closure)
|
||||
|
||||
g_clear_pointer (&thread_closure->main_context, g_main_context_unref);
|
||||
|
||||
g_clear_pointer (&thread_closure->extra_headers, (GDestroyNotify)g_variant_unref);
|
||||
|
||||
if (thread_closure->tmpdir_dfd != -1)
|
||||
close (thread_closure->tmpdir_dfd);
|
||||
|
||||
@@ -336,6 +339,16 @@ session_thread_set_cookie_jar_cb (ThreadClosure *thread_closure,
|
||||
SOUP_SESSION_FEATURE (jar));
|
||||
}
|
||||
|
||||
static void
|
||||
session_thread_set_headers_cb (ThreadClosure *thread_closure,
|
||||
gpointer data)
|
||||
{
|
||||
GVariant *headers = data;
|
||||
|
||||
g_clear_pointer (&thread_closure->extra_headers, (GDestroyNotify)g_variant_unref);
|
||||
thread_closure->extra_headers = g_variant_ref (headers);
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBSOUP_CLIENT_CERTS
|
||||
static void
|
||||
session_thread_set_tls_interaction_cb (ThreadClosure *thread_closure,
|
||||
@@ -448,6 +461,17 @@ session_thread_request_uri (ThreadClosure *thread_closure,
|
||||
return;
|
||||
}
|
||||
|
||||
if (SOUP_IS_REQUEST_HTTP (pending->request) && thread_closure->extra_headers)
|
||||
{
|
||||
glnx_unref_object SoupMessage *msg = soup_request_http_get_message ((SoupRequestHTTP*) pending->request);
|
||||
g_autoptr(GVariantIter) viter = g_variant_iter_new (thread_closure->extra_headers);
|
||||
const char *key;
|
||||
const char *value;
|
||||
|
||||
while (g_variant_iter_next (viter, "(&s&s)", &key, &value))
|
||||
soup_message_headers_append (msg->request_headers, key, value);
|
||||
}
|
||||
|
||||
if (pending->is_stream)
|
||||
{
|
||||
soup_request_send_async (pending->request,
|
||||
@@ -812,6 +836,16 @@ _ostree_fetcher_set_tls_database (OstreeFetcher *self,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_fetcher_set_extra_headers (OstreeFetcher *self,
|
||||
GVariant *extra_headers)
|
||||
{
|
||||
session_thread_idle_add (self->thread_closure,
|
||||
session_thread_set_headers_cb,
|
||||
g_variant_ref (extra_headers),
|
||||
(GDestroyNotify) g_variant_unref);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
finish_stream (OstreeFetcherPendingURI *pending,
|
||||
GCancellable *cancellable,
|
||||
|
||||
Reference in new issue
Block a user