diff options
-rw-r--r-- | rest/rest-proxy-call.c | 60 | ||||
-rw-r--r-- | tests/custom-serialize.c | 3 |
2 files changed, 49 insertions, 14 deletions
diff --git a/rest/rest-proxy-call.c b/rest/rest-proxy-call.c index 03c1874..9c3c9f3 100644 --- a/rest/rest-proxy-call.c +++ b/rest/rest-proxy-call.c @@ -734,23 +734,13 @@ set_header (gpointer key, gpointer value, gpointer user_data) soup_message_headers_replace (headers, name, value); } -static SoupMessage * -prepare_message (RestProxyCall *call, GError **error_out) +static gboolean +set_url (RestProxyCall *call) { RestProxyCallPrivate *priv; - RestProxyCallClass *call_class; - const gchar *bound_url, *user_agent; - SoupMessage *message; - GError *error = NULL; + const gchar *bound_url; priv = GET_PRIVATE (call); - call_class = REST_PROXY_CALL_GET_CLASS (call); - - /* Emit a warning if the caller is re-using RestProxyCall objects */ - if (priv->url) - { - g_warning (G_STRLOC ": re-use of RestProxyCall %p, don't do this", call); - } bound_url =_rest_proxy_get_bound_url (priv->proxy); @@ -760,6 +750,8 @@ prepare_message (RestProxyCall *call, GError **error_out) return FALSE; } + g_free (priv->url); + /* FIXME: Perhaps excessive memory duplication */ if (priv->function) { @@ -774,6 +766,27 @@ prepare_message (RestProxyCall *call, GError **error_out) priv->url = g_strdup (bound_url); } + return TRUE; +} + +static SoupMessage * +prepare_message (RestProxyCall *call, GError **error_out) +{ + RestProxyCallPrivate *priv; + RestProxyCallClass *call_class; + const gchar *user_agent; + SoupMessage *message; + GError *error = NULL; + + priv = GET_PRIVATE (call); + call_class = REST_PROXY_CALL_GET_CLASS (call); + + /* Emit a warning if the caller is re-using RestProxyCall objects */ + if (priv->url) + { + g_warning (G_STRLOC ": re-use of RestProxyCall %p, don't do this", call); + } + /* Allow an overrideable prepare function that is called before every * invocation so subclasses can do magic */ @@ -798,6 +811,16 @@ prepare_message (RestProxyCall *call, GError **error_out) return NULL; } + /* Reset priv->url as the serialize_params vcall may have called + * rest_proxy_call_set_function() + */ + if (!set_url (call)) + { + g_free (content); + g_free (content_type); + return NULL; + } + message = soup_message_new (priv->method, priv->url); if (message == NULL) { g_free (content); @@ -815,6 +838,11 @@ prepare_message (RestProxyCall *call, GError **error_out) } else if (rest_params_are_strings (priv->params)) { GHashTable *hash; + if (!set_url (call)) + { + return NULL; + } + hash = rest_params_as_string_hash_table (priv->params); message = soup_form_request_new_from_hash (priv->method, @@ -852,6 +880,12 @@ prepare_message (RestProxyCall *call, GError **error_out) } } + if (!set_url (call)) + { + soup_multipart_free (mp); + return NULL; + } + message = soup_form_request_new_from_multipart (priv->url, mp); soup_multipart_free (mp); diff --git a/tests/custom-serialize.c b/tests/custom-serialize.c index 3f8cb80..c6b801f 100644 --- a/tests/custom-serialize.c +++ b/tests/custom-serialize.c @@ -70,6 +70,7 @@ custom_proxy_call_serialize (RestProxyCall *self, *content_type = g_strdup ("application/json"); *content = g_strdup ("{}"); *content_len = strlen (*content); + rest_proxy_call_set_function (self, "ping"); return TRUE; } @@ -137,7 +138,7 @@ main (int argc, char **argv) proxy = rest_proxy_new (url, FALSE); call = g_object_new (REST_TYPE_CUSTOM_PROXY_CALL, "proxy", proxy, NULL); - rest_proxy_call_set_function (call, "ping"); + rest_proxy_call_set_function (call, "wrong-function"); if (!rest_proxy_call_sync (call, &error)) { g_printerr ("Call failed: %s\n", error->message); |