mirror of
https://github.com/lostisland/faraday.git
synced 2025-12-30 00:14:55 -05:00
When Addressable::URI is used, the `port` property will be nil unless port was explicitly specified. This made Addressable unusable in HTTPS scenarios with Net::HTTP adapters, which would default to port 80 even when the scheme was "https".
46 lines
1.1 KiB
Ruby
46 lines
1.1 KiB
Ruby
require File.expand_path('../integration', __FILE__)
|
|
require 'ostruct'
|
|
require 'uri'
|
|
|
|
module Adapters
|
|
class NetHttpTest < Faraday::TestCase
|
|
|
|
def adapter() :net_http end
|
|
|
|
behaviors = [:NonParallel]
|
|
behaviors << :Compression if RUBY_VERSION >= '1.9'
|
|
|
|
Integration.apply(self, *behaviors)
|
|
|
|
def test_no_explicit_http_port_number
|
|
url = URI('http://example.com')
|
|
url.port = nil
|
|
|
|
adapter = Faraday::Adapter::NetHttp.new
|
|
http = adapter.net_http_connection(:url => url, :request => {})
|
|
|
|
assert_equal 80, http.port
|
|
end
|
|
|
|
def test_no_explicit_https_port_number
|
|
url = URI('https://example.com')
|
|
url.port = nil
|
|
|
|
adapter = Faraday::Adapter::NetHttp.new
|
|
http = adapter.net_http_connection(:url => url, :request => {})
|
|
|
|
assert_equal 443, http.port
|
|
end
|
|
|
|
def test_explicit_port_number
|
|
url = URI('https://example.com:1234')
|
|
|
|
adapter = Faraday::Adapter::NetHttp.new
|
|
http = adapter.net_http_connection(:url => url, :request => {})
|
|
|
|
assert_equal 1234, http.port
|
|
end
|
|
|
|
end
|
|
end
|