mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-06 13:48:36 +02:00
nmcs-http: add param to GET API to set custom HTTP headers
https://bugzilla.redhat.com/show_bug.cgi?id=1821787 (cherry picked from commit053bce438b) (cherry picked from commit23c11af7f5) (cherry picked from commit912cf9e86a)
This commit is contained in:
parent
a71a5ee895
commit
e09552daff
3 changed files with 35 additions and 0 deletions
|
|
@ -120,6 +120,7 @@ typedef struct {
|
||||||
CURL *ehandle;
|
CURL *ehandle;
|
||||||
char *url;
|
char *url;
|
||||||
GString *recv_data;
|
GString *recv_data;
|
||||||
|
struct curl_slist *headers;
|
||||||
gssize max_data;
|
gssize max_data;
|
||||||
gulong cancellable_id;
|
gulong cancellable_id;
|
||||||
} EHandleData;
|
} EHandleData;
|
||||||
|
|
@ -146,6 +147,8 @@ _ehandle_free (EHandleData *edata)
|
||||||
|
|
||||||
if (edata->recv_data)
|
if (edata->recv_data)
|
||||||
g_string_free (edata->recv_data, TRUE);
|
g_string_free (edata->recv_data, TRUE);
|
||||||
|
if (edata->headers)
|
||||||
|
curl_slist_free_all (edata->headers);
|
||||||
g_free (edata->url);
|
g_free (edata->url);
|
||||||
nm_g_slice_free (edata);
|
nm_g_slice_free (edata);
|
||||||
}
|
}
|
||||||
|
|
@ -261,12 +264,14 @@ nm_http_client_get (NMHttpClient *self,
|
||||||
const char *url,
|
const char *url,
|
||||||
int timeout_msec,
|
int timeout_msec,
|
||||||
gssize max_data,
|
gssize max_data,
|
||||||
|
const char *const *http_headers,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
NMHttpClientPrivate *priv;
|
NMHttpClientPrivate *priv;
|
||||||
EHandleData *edata;
|
EHandleData *edata;
|
||||||
|
guint i;
|
||||||
|
|
||||||
g_return_if_fail (NM_IS_HTTP_CLIENT (self));
|
g_return_if_fail (NM_IS_HTTP_CLIENT (self));
|
||||||
g_return_if_fail (url);
|
g_return_if_fail (url);
|
||||||
|
|
@ -282,6 +287,7 @@ nm_http_client_get (NMHttpClient *self,
|
||||||
.recv_data = g_string_sized_new (NM_MIN (max_data, 245)),
|
.recv_data = g_string_sized_new (NM_MIN (max_data, 245)),
|
||||||
.max_data = max_data,
|
.max_data = max_data,
|
||||||
.url = g_strdup (url),
|
.url = g_strdup (url),
|
||||||
|
.headers = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
nmcs_wait_for_objects_register (edata->task);
|
nmcs_wait_for_objects_register (edata->task);
|
||||||
|
|
@ -303,6 +309,23 @@ nm_http_client_get (NMHttpClient *self,
|
||||||
curl_easy_setopt (edata->ehandle, CURLOPT_WRITEDATA, edata);
|
curl_easy_setopt (edata->ehandle, CURLOPT_WRITEDATA, edata);
|
||||||
curl_easy_setopt (edata->ehandle, CURLOPT_PRIVATE, edata);
|
curl_easy_setopt (edata->ehandle, CURLOPT_PRIVATE, edata);
|
||||||
|
|
||||||
|
if (http_headers) {
|
||||||
|
for (i = 0; http_headers[i]; ++i) {
|
||||||
|
struct curl_slist *tmp;
|
||||||
|
|
||||||
|
tmp = curl_slist_append (edata->headers,
|
||||||
|
http_headers[i]);
|
||||||
|
if (!tmp) {
|
||||||
|
curl_slist_free_all (tmp);
|
||||||
|
_LOGE ("curl: curl_slist_append() failed adding %s", http_headers[i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
edata->headers = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_setopt (edata->ehandle, CURLOPT_HTTPHEADER, edata->headers);
|
||||||
|
}
|
||||||
|
|
||||||
if (timeout_msec > 0) {
|
if (timeout_msec > 0) {
|
||||||
edata->timeout_source = _source_attach (self,
|
edata->timeout_source = _source_attach (self,
|
||||||
nm_g_timeout_source_new (timeout_msec,
|
nm_g_timeout_source_new (timeout_msec,
|
||||||
|
|
@ -363,6 +386,7 @@ nm_http_client_get_finish (NMHttpClient *self,
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GTask *task;
|
GTask *task;
|
||||||
char *uri;
|
char *uri;
|
||||||
|
const char *const *http_headers;
|
||||||
NMHttpClientPollGetCheckFcn check_fcn;
|
NMHttpClientPollGetCheckFcn check_fcn;
|
||||||
gpointer check_user_data;
|
gpointer check_user_data;
|
||||||
GBytes *response_data;
|
GBytes *response_data;
|
||||||
|
|
@ -379,6 +403,7 @@ _poll_get_data_free (gpointer data)
|
||||||
g_free (poll_get_data->uri);
|
g_free (poll_get_data->uri);
|
||||||
|
|
||||||
nm_clear_pointer (&poll_get_data->response_data, g_bytes_unref);
|
nm_clear_pointer (&poll_get_data->response_data, g_bytes_unref);
|
||||||
|
g_strfreev ((char **) poll_get_data->http_headers);
|
||||||
|
|
||||||
nm_g_slice_free (poll_get_data);
|
nm_g_slice_free (poll_get_data);
|
||||||
}
|
}
|
||||||
|
|
@ -398,6 +423,7 @@ _poll_get_probe_start_fcn (GCancellable *cancellable,
|
||||||
poll_get_data->uri,
|
poll_get_data->uri,
|
||||||
poll_get_data->request_timeout_ms,
|
poll_get_data->request_timeout_ms,
|
||||||
poll_get_data->request_max_data,
|
poll_get_data->request_max_data,
|
||||||
|
poll_get_data->http_headers,
|
||||||
cancellable,
|
cancellable,
|
||||||
callback,
|
callback,
|
||||||
user_data);
|
user_data);
|
||||||
|
|
@ -477,6 +503,7 @@ nm_http_client_poll_get (NMHttpClient *self,
|
||||||
gssize request_max_data,
|
gssize request_max_data,
|
||||||
int poll_timeout_ms,
|
int poll_timeout_ms,
|
||||||
int ratelimit_timeout_ms,
|
int ratelimit_timeout_ms,
|
||||||
|
const char *const *http_headers,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
NMHttpClientPollGetCheckFcn check_fcn,
|
NMHttpClientPollGetCheckFcn check_fcn,
|
||||||
gpointer check_user_data,
|
gpointer check_user_data,
|
||||||
|
|
@ -503,6 +530,7 @@ nm_http_client_poll_get (NMHttpClient *self,
|
||||||
.check_fcn = check_fcn,
|
.check_fcn = check_fcn,
|
||||||
.check_user_data = check_user_data,
|
.check_user_data = check_user_data,
|
||||||
.response_code = -1,
|
.response_code = -1,
|
||||||
|
.http_headers = NM_CAST_STRV_CC (g_strdupv ((char **) http_headers)),
|
||||||
};
|
};
|
||||||
|
|
||||||
nmcs_wait_for_objects_register (poll_get_data->task);
|
nmcs_wait_for_objects_register (poll_get_data->task);
|
||||||
|
|
@ -681,6 +709,7 @@ static void
|
||||||
nm_http_client_init (NMHttpClient *self)
|
nm_http_client_init (NMHttpClient *self)
|
||||||
{
|
{
|
||||||
NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE (self);
|
NMHttpClientPrivate *priv = NM_HTTP_CLIENT_GET_PRIVATE (self);
|
||||||
|
|
||||||
priv->source_sockets_hashtable = g_hash_table_new_full (nm_direct_hash,
|
priv->source_sockets_hashtable = g_hash_table_new_full (nm_direct_hash,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ void nm_http_client_get (NMHttpClient *self,
|
||||||
const char *uri,
|
const char *uri,
|
||||||
int timeout_msec,
|
int timeout_msec,
|
||||||
gssize max_data,
|
gssize max_data,
|
||||||
|
const char *const *http_headers,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
@ -50,6 +51,7 @@ void nm_http_client_poll_get (NMHttpClient *self,
|
||||||
gssize request_max_data,
|
gssize request_max_data,
|
||||||
int poll_timeout_ms,
|
int poll_timeout_ms,
|
||||||
int ratelimit_timeout_ms,
|
int ratelimit_timeout_ms,
|
||||||
|
const char *const *http_headers,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
NMHttpClientPollGetCheckFcn check_fcn,
|
NMHttpClientPollGetCheckFcn check_fcn,
|
||||||
gpointer check_user_data,
|
gpointer check_user_data,
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,7 @@ detect (NMCSProvider *provider,
|
||||||
256*1024,
|
256*1024,
|
||||||
7000,
|
7000,
|
||||||
1000,
|
1000,
|
||||||
|
NULL,
|
||||||
g_task_get_cancellable (task),
|
g_task_get_cancellable (task),
|
||||||
_detect_get_meta_data_check_cb,
|
_detect_get_meta_data_check_cb,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
@ -396,6 +397,7 @@ _get_config_metadata_ready_cb (GObject *source,
|
||||||
512*1024,
|
512*1024,
|
||||||
10000,
|
10000,
|
||||||
1000,
|
1000,
|
||||||
|
NULL,
|
||||||
iface_data->cancellable,
|
iface_data->cancellable,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
@ -413,6 +415,7 @@ _get_config_metadata_ready_cb (GObject *source,
|
||||||
512*1024,
|
512*1024,
|
||||||
10000,
|
10000,
|
||||||
1000,
|
1000,
|
||||||
|
NULL,
|
||||||
iface_data->cancellable,
|
iface_data->cancellable,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
|
|
@ -529,6 +532,7 @@ get_config (NMCSProvider *provider,
|
||||||
256 * 1024,
|
256 * 1024,
|
||||||
15000,
|
15000,
|
||||||
1000,
|
1000,
|
||||||
|
NULL,
|
||||||
g_task_get_cancellable (get_config_data->task),
|
g_task_get_cancellable (get_config_data->task),
|
||||||
_get_config_metadata_ready_check,
|
_get_config_metadata_ready_check,
|
||||||
metadata_data,
|
metadata_data,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue