Sha256: c6ea38cf9e89df05487bcde3abc6ff5caf64a6dd9e45505dc33e3d615c17fa26

Contents?: true

Size: 1.19 KB

Versions: 27

Compression:

Stored size: 1.19 KB

Contents

# TODO: Remove this monkey patch once ruby 1.9.3+ is the minimum supported version.
#
# This patch backports URI#hostname to ruby 1.9.2 and older.
# URI#hostname is used for IPv6 support in Excon.
#
# URI#hostname was added in stdlib in v1_9_3_0 in this commit:
#   https://github.com/ruby/ruby/commit/5fd45a4b79dd26f9e7b6dc41142912df911e4d7d
#
# Addressable::URI is also an URI parser accepted in some parts of Excon.
# Addressable::URI#hostname was added in addressable-2.3.5+ in this commit:
#   https://github.com/sporkmonger/addressable/commit/1b94abbec1f914d5f707c92a10efbb9e69aab65e
#
# Users who want to use Addressable::URI to parse URIs must upgrade to 2.3.5 or newer.
require 'uri'
unless URI("http://foo/bar").respond_to?(:hostname)
  module URI
    class Generic
      # extract the host part of the URI and unwrap brackets for IPv6 addresses.
      #
      # This method is same as URI::Generic#host except
      # brackets for IPv6 (and future IP) addresses are removed.
      #
      # u = URI("http://[::1]/bar")
      # p u.hostname      #=> "::1"
      # p u.host          #=> "[::1]"
      #
      def hostname
        v = self.host
        /\A\[(.*)\]\z/ =~ v ? $1 : v
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
excon-0.51.0 lib/excon/extensions/uri.rb
excon-0.50.1 lib/excon/extensions/uri.rb
excon-0.50.0 lib/excon/extensions/uri.rb
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/excon-0.45.4/lib/excon/extensions/uri.rb
excon-0.49.0 lib/excon/extensions/uri.rb
excon-0.48.0 lib/excon/extensions/uri.rb
excon-0.47.0 lib/excon/extensions/uri.rb
excon-0.46.0 lib/excon/extensions/uri.rb
framed_rails-0.2.0 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
framed_rails-0.1.7 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/excon-0.45.4/lib/excon/extensions/uri.rb
framed_rails-0.1.5 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
framed_rails-0.1.4 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
framed_rails-0.1.3 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
framed_rails-0.1.2 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
framed_rails-0.1.0 vendor/gems/excon-0.45.3/lib/excon/extensions/uri.rb
excon-0.45.4 lib/excon/extensions/uri.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/excon-0.45.3/lib/excon/extensions/uri.rb
excon-0.45.3 lib/excon/extensions/uri.rb
excon-0.45.2 lib/excon/extensions/uri.rb