summaryrefslogtreecommitdiff
path: root/rest/oauth-proxy-call.c
diff options
context:
space:
mode:
authorTimm Bäder <baedert@gmail.com>2013-02-08 22:47:13 +0100
committerRoss Burton <ross.burton@intel.com>2013-02-19 19:47:44 +0000
commit94c72cf7bbaa33bad91652961768baf1293e5181 (patch)
treee4929634ba53f237a2b2dc59f865059c0eab0ee8 /rest/oauth-proxy-call.c
parentf645ce5f7d3b6e7306f58fa5c8f31ee4d533cd9b (diff)
downloadlibrest-94c72cf7bbaa33bad91652961768baf1293e5181.tar.gz
Support multipart/form-data requests in OAuthProxyCall
If the user uploads a file using a multipart/form-data request, the that parameter must not be used to encode the request.
Diffstat (limited to 'rest/oauth-proxy-call.c')
-rw-r--r--rest/oauth-proxy-call.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/rest/oauth-proxy-call.c b/rest/oauth-proxy-call.c
index 884c8c2..63c859f 100644
--- a/rest/oauth-proxy-call.c
+++ b/rest/oauth-proxy-call.c
@@ -120,8 +120,12 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
OAuthProxyPrivate *priv;
RestProxyCallPrivate *callpriv;
char *key, *signature, *ep, *eep;
+ const char *content_type;
GString *text;
GHashTable *all_params;
+ RestParamsIter params_iter;
+ RestParam *param;
+ gboolean encode_query_params = TRUE;
priv = PROXY_GET_PRIVATE (proxy);
callpriv = call->priv;
@@ -147,11 +151,28 @@ sign_hmac (OAuthProxy *proxy, RestProxyCall *call, GHashTable *oauth_params)
}
g_string_append_c (text, '&');
+
+
+ /* If one of the call's parameters is a multipart/form-data parameter, the
+ signature base string must be generated with only the oauth parameters */
+ rest_params_iter_init(&params_iter, callpriv->params);
+ while(rest_params_iter_next(&params_iter, (gpointer)&key, (gpointer)&param)) {
+ content_type = rest_param_get_content_type(param);
+ if (strcmp(content_type, "multipart/form-data") == 0){
+ encode_query_params = FALSE;
+ break;
+ }
+ }
+
+
+
/* Merge the OAuth parameters with the query parameters */
all_params = g_hash_table_new (g_str_hash, g_str_equal);
merge_hashes (all_params, oauth_params);
- if (!priv->oauth_echo)
- merge_params (all_params, callpriv->params);
+ if (encode_query_params && !priv->oauth_echo) {
+ merge_params (all_params, callpriv->params);
+ }
+
ep = encode_params (all_params);
eep = OAUTH_ENCODE_STRING (ep);