Skip to content

Commit e773454

Browse files
committed
Correct bug detecting content type and parsing json responses
This is likely a breaking bug fix, since requests will now _correctly_ parse the response body as json and return a hash, instead of returning the body as a string. Fixes #34
1 parent 12cf820 commit e773454

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

lib/fog/aliyun/compute.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,18 @@ def reload
300300

301301
def request(params)
302302
begin
303-
response = @connection.request(params.merge(headers: {
303+
headers = {
304304
'Content-Type' => 'application/json',
305305
'Accept' => 'application/json',
306306
'X-Auth-Token' => @auth_token
307-
}.merge!(params[:headers] || {}),
308-
path: "#{@path}/#{params[:path]}",
309-
query: params[:query]))
307+
}.merge!(params[:headers] || {})
308+
309+
request_params = params.merge(
310+
headers: headers,
311+
path: "#{@path}/#{params[:path]}",
312+
query: params[:query])
313+
314+
response = @connection.request(request_params)
310315
rescue Excon::Errors::HTTPStatusError => error
311316
raise case error
312317
when Excon::Errors::NotFound
@@ -316,7 +321,7 @@ def request(params)
316321
end
317322
end
318323

319-
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
324+
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type').start_with?('application/json')
320325

321326
response
322327
end
@@ -339,7 +344,7 @@ def VPCrequest(params)
339344
end
340345
end
341346

342-
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type') == 'application/json'
347+
response.body = Fog::JSON.decode(response.body) if !response.body.empty? && response.get_header('Content-Type').start_with?('application/json')
343348

344349
response
345350
end

lib/fog/aliyun/models/compute/servers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Servers < Fog::Collection
1010
model Fog::Compute::Aliyun::Server
1111

1212
def all(options = {})
13-
Fog::JSON.decode(service.list_servers(options).body)['Instances']['Instance']
13+
service.list_servers(options).body['Instances']['Instance']
1414
end
1515

1616
# Creates a new server and populates ssh keys

0 commit comments

Comments
 (0)