Skip to content

Commit b7f7608

Browse files
author
Rodney Brown
committed
Refactors assignment of https:// protocol
1 parent edead63 commit b7f7608

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

lib/xclarity_client/xclarity_base.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'faraday'
22
require 'json'
33
require 'uri'
4+
require 'uri/https'
45

56
module XClarityClient
67
class XClarityBase
@@ -14,12 +15,16 @@ def initialize(conf, uri)
1415

1516
def connection_builder(conf, uri)
1617
$lxca_log.info "XClarityClient::XClarityBase connection_builder", "Creating connection to #{conf.host + uri}"
17-
#Building configuration
18-
host = conf.host
19-
if !host.start_with?('https://') && !host.start_with?('http://')
20-
host = "https://#{host}"
18+
# Building configuration, convert to https if protocol not specified
19+
hostname = URI.parse(conf.host)
20+
unless hostname.scheme
21+
hostname = URI::HTTPS.build({ :host => hostname.host,
22+
:port => hostname.port,
23+
:path => hostname.path,
24+
:query => hostname.query,
25+
:fragment => hostname.fragment })
2126
end
22-
@conn = Faraday.new(:url => "#{host}#{uri}") do |faraday|
27+
@conn = Faraday.new(:url => "#{hostname}#{uri}") do |faraday|
2328
faraday.request :url_encoded # form-encode POST params
2429
faraday.response :logger # log requests to STDOUT -- This line, should be uncommented if you wanna inspect the URL Request
2530
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP

0 commit comments

Comments
 (0)