lib/baidubce/utils/utils.rb in baidubce-sdk-0.9.0 vs lib/baidubce/utils/utils.rb in baidubce-sdk-0.9.1
- old
+ new
@@ -21,13 +21,18 @@
module Baidubce
class Utils
+ DEFAULT_CNAME_LIKE_LIST = [".cdn.bcebos.com"]
+
# parse protocol, host, port from endpoint in config.
- def self.parse_url_host(config)
+ def self.parse_url_host(config, use_backup_endpoint=false)
endpoint = config.endpoint
+ if use_backup_endpoint
+ endpoint = config.backup_endpoint
+ end
unless endpoint.include?"://"
protocol = config.protocol.downcase
raise "Invalid protocol #{protocol}." if protocol != "http" && protocol != 'https'
endpoint = sprintf("%s://%s", protocol, endpoint)
end
@@ -89,11 +94,11 @@
md5.base64digest
end
def self.generate_response(headers, body, return_body)
return body if return_body
- return generate_headers(headers) if body.empty?
+ return generate_headers(headers) if body.to_s.empty?
ret = JSON.parse(body)
return ret
rescue JSON::ParserError
return body
end
@@ -115,9 +120,16 @@
end
ret
end
resp_headers['user-metadata'] = user_metadata unless user_metadata.empty?
resp_headers
+ end
+
+ def self.is_cname_like_host(host)
+ DEFAULT_CNAME_LIKE_LIST.each do |suffix|
+ return true if host.to_s.downcase.end_with?(suffix)
+ end
+ return false
end
end
end