diff --git a/lib/httpx/adapters/faraday.rb b/lib/httpx/adapters/faraday.rb index 759162a6..4d4fad31 100644 --- a/lib/httpx/adapters/faraday.rb +++ b/lib/httpx/adapters/faraday.rb @@ -80,27 +80,36 @@ module Faraday timeout_options[:connect_timeout] = sec end - ssl_options = {} - - unless env.ssl.verify.nil? - ssl_options[:verify_mode] = env.ssl.verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE - end - - ssl_options[:ca_file] = env.ssl.ca_file if env.ssl.ca_file - ssl_options[:ca_path] = env.ssl.ca_path if env.ssl.ca_path - ssl_options[:cert_store] = env.ssl.cert_store if env.ssl.cert_store - ssl_options[:cert] = env.ssl.client_cert if env.ssl.client_cert - ssl_options[:key] = env.ssl.client_key if env.ssl.client_key - ssl_options[:ssl_version] = env.ssl.version if env.ssl.version - ssl_options[:verify_depth] = env.ssl.verify_depth if env.ssl.verify_depth - ssl_options[:min_version] = env.ssl.min_version if env.ssl.min_version - ssl_options[:max_version] = env.ssl.max_version if env.ssl.max_version - { - ssl: ssl_options, + ssl: ssl_options_from_env(env), timeout: timeout_options, } end + + if defined?(::OpenSSL) + def ssl_options_from_env(env) + ssl_options = {} + + unless env.ssl.verify.nil? + ssl_options[:verify_mode] = env.ssl.verify ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE + end + + ssl_options[:ca_file] = env.ssl.ca_file if env.ssl.ca_file + ssl_options[:ca_path] = env.ssl.ca_path if env.ssl.ca_path + ssl_options[:cert_store] = env.ssl.cert_store if env.ssl.cert_store + ssl_options[:cert] = env.ssl.client_cert if env.ssl.client_cert + ssl_options[:key] = env.ssl.client_key if env.ssl.client_key + ssl_options[:ssl_version] = env.ssl.version if env.ssl.version + ssl_options[:verify_depth] = env.ssl.verify_depth if env.ssl.verify_depth + ssl_options[:min_version] = env.ssl.min_version if env.ssl.min_version + ssl_options[:max_version] = env.ssl.max_version if env.ssl.max_version + ssl_options + end + else + def ssl_options_from_env(*) + {} + end + end end include RequestMixin diff --git a/lib/httpx/io.rb b/lib/httpx/io.rb index 83630c28..e4bed6c9 100644 --- a/lib/httpx/io.rb +++ b/lib/httpx/io.rb @@ -4,4 +4,8 @@ require "socket" require "httpx/io/udp" require "httpx/io/tcp" require "httpx/io/unix" -require "httpx/io/ssl" + +begin + require "httpx/io/ssl" +rescue LoadError +end diff --git a/test/support/requests/plugins/follow_redirects.rb b/test/support/requests/plugins/follow_redirects.rb index 0e5078b2..7fb92f61 100644 --- a/test/support/requests/plugins/follow_redirects.rb +++ b/test/support/requests/plugins/follow_redirects.rb @@ -23,6 +23,16 @@ module Requests verify_status(response, 304) end + def test_plugin_follow_redirects_relative_path + session = HTTPX.plugin(:follow_redirects) + uri = redirect_uri("../get") + + redirect_response = session.get(uri) + body = json_body(redirect_response) + assert body.key?("url"), "url should be set" + assert body["url"] == redirect_location, "url should have been the given redirection url" + end + def test_plugin_follow_redirects_default_max_redirects session = HTTPX.plugin(:follow_redirects)