diff --git a/lib/httpx/extensions.rb b/lib/httpx/extensions.rb index 110fac1f..000f02d9 100644 --- a/lib/httpx/extensions.rb +++ b/lib/httpx/extensions.rb @@ -55,26 +55,35 @@ module HTTPX end module URIExtensions - refine URI::Generic do - def authority - port_string = port == default_port ? nil : ":#{port}" - "#{host}#{port_string}" - end + URI_KLASSES = case RUBY_ENGINE + when "jruby" + [URI::Generic, URI::HTTP, URI::HTTPS] + else + [URI::Generic] + end - def origin - "#{scheme}://#{authority}" - end + URI_KLASSES.each do |klass| + refine klass do + def authority + port_string = port == default_port ? nil : ":#{port}" + "#{host}#{port_string}" + end - def altsvc_match?(uri) - uri = URI.parse(uri) - self == uri || begin - case scheme - when 'h2' - uri.scheme == "https" && - host == uri.host && - (port || default_port) == (uri.port || uri.default_port) - else - false + def origin + "#{scheme}://#{authority}" + end + + def altsvc_match?(uri) + uri = URI.parse(uri) + self == uri || begin + case scheme + when 'h2' + uri.scheme == "https" && + host == uri.host && + (port || default_port) == (uri.port || uri.default_port) + else + false + end end end end