Skip to content

Commit

Permalink
Avoid passing an empty 'data' object to restler.get calls.
Browse files Browse the repository at this point in the history
Restler changes Content-Type to 'application/x-www-form-urlencoded' even
for GET requests, as long as data is not a string. That breaks some nova
API calls when Mitaka nova-api is used, as it now expects to get
"application/json" for all queries. Make sure we pass data object only
for POST and PUT calls.

Change-Id: Ieaf1622dec703404d9672681a9cd0d35199326d7
Closes-Bug: 1591393
  • Loading branch information
kklimonda committed Jun 10, 2016
1 parent c7f397c commit f10620e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/serverroot/common/rest.api.js
Expand Up @@ -232,11 +232,9 @@ APIServer.prototype.makeCall = function (restApi, params, callback, isRetry)
var self = this;
var reqUrl = null;
var options = {};
var data = commonUtils.getApiPostData(params['path'], params['data']);
var method = params['method'];
var xml2jsSettings = params['xml2jsSettings'];
options['headers'] = params['headers'] || {};
options['data'] = data || {};
options['method'] = method;
options['headers']['Content-Length'] = (data) ? data.toString().length : 0;

Expand All @@ -245,8 +243,12 @@ APIServer.prototype.makeCall = function (restApi, params, callback, isRetry)
we need to specify the Content-Type as App/JSON with JSON.stringify
of the data, otherwise, restler treats it as
application/x-www-form-urlencoded as Content-Type and encodes
the data accordingly
the data accordingly. Restler also changes Content-Type when
an empty data object is passed for GET queries, so make sure
we are don't pass it.
*/
var data = commonUtils.getApiPostData(params['path'], params['data']);
options['data'] = data || {};
options['headers']['Content-Type'] = 'application/json';
}
params = self.updateDiscoveryServiceParams(params);
Expand Down

0 comments on commit f10620e

Please sign in to comment.