From f10620ede1f9f28858a9b418ec26093c57f00c41 Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Thu, 9 Jun 2016 13:38:18 -0700 Subject: [PATCH] Avoid passing an empty 'data' object to restler.get calls. 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 --- src/serverroot/common/rest.api.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/serverroot/common/rest.api.js b/src/serverroot/common/rest.api.js index cec44a7e5..5046edb09 100644 --- a/src/serverroot/common/rest.api.js +++ b/src/serverroot/common/rest.api.js @@ -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; @@ -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);