Skip to content

Commit

Permalink
Correct bug detecting content type and parsing json responses
Browse files Browse the repository at this point in the history
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 fog#34
  • Loading branch information
DigitallyBorn committed Feb 26, 2019
1 parent 12cf820 commit e773454
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions lib/fog/aliyun/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,18 @@ def reload

def request(params)
begin
response = @connection.request(params.merge(headers: {
headers = {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
path: "#{@path}/#{params[:path]}",
query: params[:query]))
}.merge!(params[:headers] || {})

request_params = params.merge(
headers: headers,
path: "#{@path}/#{params[:path]}",
query: params[:query])

response = @connection.request(request_params)
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Expand All @@ -316,7 +321,7 @@ def request(params)
end
end

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

response
end
Expand All @@ -339,7 +344,7 @@ def VPCrequest(params)
end
end

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

response
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aliyun/models/compute/servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Servers < Fog::Collection
model Fog::Compute::Aliyun::Server

def all(options = {})
Fog::JSON.decode(service.list_servers(options).body)['Instances']['Instance']
service.list_servers(options).body['Instances']['Instance']
end

# Creates a new server and populates ssh keys
Expand Down

0 comments on commit e773454

Please sign in to comment.