mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improve docs for URI library
* lib/uri/generic.rb: [DOC] fix invalid example code to make it syntax highlighted; drop unnecessary `puts', `p'; adapt to current inspect format without Object id; do not display unnecessary return values in examples; fix or prevent unintended description lists; fix broken RDoc; fix grammar and typos. * lib/uri.rb: ditto. * lib/uri/common.rb: ditto. * lib/uri/file.rb: ditto. * lib/uri/ftp.rb: ditto. * lib/uri/http.rb: ditto. * lib/uri/ldap.rb: ditto. * lib/uri/mailto.rb: ditto. * lib/uri/rfc2396_parser.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c04881f94a
commit
300b22dc22
9 changed files with 343 additions and 372 deletions
42
lib/uri.rb
42
lib/uri.rb
|
@ -1,34 +1,28 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
# URI is a module providing classes to handle Uniform Resource Identifiers
|
# URI is a module providing classes to handle Uniform Resource Identifiers
|
||||||
# (RFC2396[http://tools.ietf.org/html/rfc2396])
|
# (RFC2396[http://tools.ietf.org/html/rfc2396]).
|
||||||
#
|
#
|
||||||
# == Features
|
# == Features
|
||||||
#
|
#
|
||||||
# * Uniform handling of handling URIs
|
# * Uniform way of handling URIs.
|
||||||
# * Flexibility to introduce custom URI schemes
|
# * Flexibility to introduce custom URI schemes.
|
||||||
# * Flexibility to have an alternate URI::Parser (or just different patterns
|
# * Flexibility to have an alternate URI::Parser (or just different patterns
|
||||||
# and regexp's)
|
# and regexp's).
|
||||||
#
|
#
|
||||||
# == Basic example
|
# == Basic example
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
|
# uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
|
||||||
# #=> #<URI::HTTP:0x00000000b14880
|
# #=> #<URI::HTTP http://foo.com/posts?id=30&limit=5#time=1305298413>
|
||||||
# URL:http://foo.com/posts?id=30&limit=5#time=1305298413>
|
|
||||||
# uri.scheme
|
|
||||||
# #=> "http"
|
|
||||||
# uri.host
|
|
||||||
# #=> "foo.com"
|
|
||||||
# uri.path
|
|
||||||
# #=> "/posts"
|
|
||||||
# uri.query
|
|
||||||
# #=> "id=30&limit=5"
|
|
||||||
# uri.fragment
|
|
||||||
# #=> "time=1305298413"
|
|
||||||
#
|
#
|
||||||
# uri.to_s
|
# uri.scheme #=> "http"
|
||||||
# #=> "http://foo.com/posts?id=30&limit=5#time=1305298413"
|
# uri.host #=> "foo.com"
|
||||||
|
# uri.path #=> "/posts"
|
||||||
|
# uri.query #=> "id=30&limit=5"
|
||||||
|
# uri.fragment #=> "time=1305298413"
|
||||||
|
#
|
||||||
|
# uri.to_s #=> "http://foo.com/posts?id=30&limit=5#time=1305298413"
|
||||||
#
|
#
|
||||||
# == Adding custom URIs
|
# == Adding custom URIs
|
||||||
#
|
#
|
||||||
|
@ -41,18 +35,18 @@
|
||||||
# #=> URI::RSYNC
|
# #=> URI::RSYNC
|
||||||
#
|
#
|
||||||
# URI.scheme_list
|
# URI.scheme_list
|
||||||
# #=> {"FILE"=>URI::File, "FTP"=>URI::FTP, "HTTP"=>URI::HTTP, "HTTPS"=>URI::HTTPS,
|
# #=> {"FILE"=>URI::File, "FTP"=>URI::FTP, "HTTP"=>URI::HTTP,
|
||||||
# "LDAP"=>URI::LDAP, "LDAPS"=>URI::LDAPS, "MAILTO"=>URI::MailTo,
|
# # "HTTPS"=>URI::HTTPS, "LDAP"=>URI::LDAP, "LDAPS"=>URI::LDAPS,
|
||||||
# "RSYNC"=>URI::RSYNC}
|
# # "MAILTO"=>URI::MailTo, "RSYNC"=>URI::RSYNC}
|
||||||
#
|
#
|
||||||
# uri = URI("rsync://rsync.foo.com")
|
# uri = URI("rsync://rsync.foo.com")
|
||||||
# #=> #<URI::RSYNC:0x00000000f648c8 URL:rsync://rsync.foo.com>
|
# #=> #<URI::RSYNC rsync://rsync.foo.com>
|
||||||
#
|
#
|
||||||
# == RFC References
|
# == RFC References
|
||||||
#
|
#
|
||||||
# A good place to view an RFC spec is http://www.ietf.org/rfc.html
|
# A good place to view an RFC spec is http://www.ietf.org/rfc.html.
|
||||||
#
|
#
|
||||||
# Here is a list of all related RFC's.
|
# Here is a list of all related RFC's:
|
||||||
# - RFC822[http://tools.ietf.org/html/rfc822]
|
# - RFC822[http://tools.ietf.org/html/rfc822]
|
||||||
# - RFC1738[http://tools.ietf.org/html/rfc1738]
|
# - RFC1738[http://tools.ietf.org/html/rfc1738]
|
||||||
# - RFC2255[http://tools.ietf.org/html/rfc2255]
|
# - RFC2255[http://tools.ietf.org/html/rfc2255]
|
||||||
|
|
|
@ -61,7 +61,7 @@ module URI
|
||||||
module_function :make_components_hash
|
module_function :make_components_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
# module for escaping unsafe characters with codes.
|
# Module for escaping unsafe characters with codes.
|
||||||
module Escape
|
module Escape
|
||||||
#
|
#
|
||||||
# == Synopsis
|
# == Synopsis
|
||||||
|
@ -90,13 +90,12 @@ module URI
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# enc_uri = URI.escape("http://example.com/?a=\11\15")
|
# enc_uri = URI.escape("http://example.com/?a=\11\15")
|
||||||
# p enc_uri
|
|
||||||
# # => "http://example.com/?a=%09%0D"
|
# # => "http://example.com/?a=%09%0D"
|
||||||
#
|
#
|
||||||
# p URI.unescape(enc_uri)
|
# URI.unescape(enc_uri)
|
||||||
# # => "http://example.com/?a=\t\r"
|
# # => "http://example.com/?a=\t\r"
|
||||||
#
|
#
|
||||||
# p URI.escape("@?@!", "!?")
|
# URI.escape("@?@!", "!?")
|
||||||
# # => "@%3F@%21"
|
# # => "@%3F@%21"
|
||||||
#
|
#
|
||||||
def escape(*arg)
|
def escape(*arg)
|
||||||
|
@ -112,7 +111,7 @@ module URI
|
||||||
# == Args
|
# == Args
|
||||||
#
|
#
|
||||||
# +str+::
|
# +str+::
|
||||||
# Unescapes the string.
|
# String to unescape.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
|
@ -125,10 +124,9 @@ module URI
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# enc_uri = URI.escape("http://example.com/?a=\11\15")
|
# enc_uri = URI.escape("http://example.com/?a=\11\15")
|
||||||
# p enc_uri
|
|
||||||
# # => "http://example.com/?a=%09%0D"
|
# # => "http://example.com/?a=%09%0D"
|
||||||
#
|
#
|
||||||
# p URI.unescape(enc_uri)
|
# URI.unescape(enc_uri)
|
||||||
# # => "http://example.com/?a=\t\r"
|
# # => "http://example.com/?a=\t\r"
|
||||||
#
|
#
|
||||||
def unescape(*arg)
|
def unescape(*arg)
|
||||||
|
@ -142,7 +140,7 @@ module URI
|
||||||
include REGEXP
|
include REGEXP
|
||||||
|
|
||||||
@@schemes = {}
|
@@schemes = {}
|
||||||
# Returns a Hash of the defined schemes
|
# Returns a Hash of the defined schemes.
|
||||||
def self.scheme_list
|
def self.scheme_list
|
||||||
@@schemes
|
@@schemes
|
||||||
end
|
end
|
||||||
|
@ -178,21 +176,21 @@ module URI
|
||||||
#
|
#
|
||||||
# Splits the string on following parts and returns array with result:
|
# Splits the string on following parts and returns array with result:
|
||||||
#
|
#
|
||||||
# * Scheme
|
# * Scheme
|
||||||
# * Userinfo
|
# * Userinfo
|
||||||
# * Host
|
# * Host
|
||||||
# * Port
|
# * Port
|
||||||
# * Registry
|
# * Registry
|
||||||
# * Path
|
# * Path
|
||||||
# * Opaque
|
# * Opaque
|
||||||
# * Query
|
# * Query
|
||||||
# * Fragment
|
# * Fragment
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# p URI.split("http://www.ruby-lang.org/")
|
# URI.split("http://www.ruby-lang.org/")
|
||||||
# # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
|
# # => ["http", nil, "www.ruby-lang.org", nil, nil, "/", nil, nil, nil]
|
||||||
#
|
#
|
||||||
def self.split(uri)
|
def self.split(uri)
|
||||||
|
@ -215,7 +213,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Raises
|
# == Raises
|
||||||
#
|
#
|
||||||
# URI::InvalidURIError
|
# URI::InvalidURIError::
|
||||||
# Raised if URI given is not a correct one.
|
# Raised if URI given is not a correct one.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
|
@ -223,11 +221,10 @@ module URI
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://www.ruby-lang.org/")
|
# uri = URI.parse("http://www.ruby-lang.org/")
|
||||||
# p uri
|
# # => #<URI::HTTP http://www.ruby-lang.org/>
|
||||||
# # => #<URI::HTTP:0x202281be URL:http://www.ruby-lang.org/>
|
# uri.scheme
|
||||||
# p uri.scheme
|
|
||||||
# # => "http"
|
# # => "http"
|
||||||
# p uri.host
|
# uri.host
|
||||||
# # => "www.ruby-lang.org"
|
# # => "www.ruby-lang.org"
|
||||||
#
|
#
|
||||||
# It's recommended to first ::escape the provided +uri_str+ if there are any
|
# It's recommended to first ::escape the provided +uri_str+ if there are any
|
||||||
|
@ -255,21 +252,20 @@ module URI
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# p URI.join("http://example.com/","main.rbx")
|
# URI.join("http://example.com/","main.rbx")
|
||||||
# # => #<URI::HTTP:0x2022ac02 URL:http://example.com/main.rbx>
|
# # => #<URI::HTTP http://example.com/main.rbx>
|
||||||
#
|
#
|
||||||
# p URI.join('http://example.com', 'foo')
|
# URI.join('http://example.com', 'foo')
|
||||||
# # => #<URI::HTTP:0x01ab80a0 URL:http://example.com/foo>
|
# # => #<URI::HTTP http://example.com/foo>
|
||||||
#
|
#
|
||||||
# p URI.join('http://example.com', '/foo', '/bar')
|
# URI.join('http://example.com', '/foo', '/bar')
|
||||||
# # => #<URI::HTTP:0x01aaf0b0 URL:http://example.com/bar>
|
# # => #<URI::HTTP http://example.com/bar>
|
||||||
#
|
#
|
||||||
# p URI.join('http://example.com', '/foo', 'bar')
|
# URI.join('http://example.com', '/foo', 'bar')
|
||||||
# # => #<URI::HTTP:0x801a92af0 URL:http://example.com/bar>
|
# # => #<URI::HTTP http://example.com/bar>
|
||||||
#
|
|
||||||
# p URI.join('http://example.com', '/foo/', 'bar')
|
|
||||||
# # => #<URI::HTTP:0x80135a3a0 URL:http://example.com/foo/bar>
|
|
||||||
#
|
#
|
||||||
|
# URI.join('http://example.com', '/foo/', 'bar')
|
||||||
|
# # => #<URI::HTTP http://example.com/foo/bar>
|
||||||
#
|
#
|
||||||
def self.join(*str)
|
def self.join(*str)
|
||||||
RFC3986_PARSER.join(*str)
|
RFC3986_PARSER.join(*str)
|
||||||
|
@ -285,7 +281,7 @@ module URI
|
||||||
# +str+::
|
# +str+::
|
||||||
# String to extract URIs from.
|
# String to extract URIs from.
|
||||||
# +schemes+::
|
# +schemes+::
|
||||||
# Limit URI matching to a specific schemes.
|
# Limit URI matching to specific schemes.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
|
@ -316,6 +312,7 @@ module URI
|
||||||
# whose scheme is one of the match_schemes.
|
# whose scheme is one of the match_schemes.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
|
#
|
||||||
# Returns a Regexp object which matches to URI-like strings.
|
# Returns a Regexp object which matches to URI-like strings.
|
||||||
# The Regexp object returned by this method includes arbitrary
|
# The Regexp object returned by this method includes arbitrary
|
||||||
# number of capture group (parentheses). Never rely on it's number.
|
# number of capture group (parentheses). Never rely on it's number.
|
||||||
|
@ -328,7 +325,7 @@ module URI
|
||||||
# html_string.slice(URI.regexp)
|
# html_string.slice(URI.regexp)
|
||||||
#
|
#
|
||||||
# # remove ftp URIs
|
# # remove ftp URIs
|
||||||
# html_string.sub(URI.regexp(['ftp'])
|
# html_string.sub(URI.regexp(['ftp']), '')
|
||||||
#
|
#
|
||||||
# # You should not rely on the number of parentheses
|
# # You should not rely on the number of parentheses
|
||||||
# html_string.scan(URI.regexp) do |*matches|
|
# html_string.scan(URI.regexp) do |*matches|
|
||||||
|
@ -360,7 +357,7 @@ module URI
|
||||||
HTML5ASCIIINCOMPAT = defined? Encoding::UTF_7 ? [Encoding::UTF_7, Encoding::UTF_16BE, Encoding::UTF_16LE,
|
HTML5ASCIIINCOMPAT = defined? Encoding::UTF_7 ? [Encoding::UTF_7, Encoding::UTF_16BE, Encoding::UTF_16LE,
|
||||||
Encoding::UTF_32BE, Encoding::UTF_32LE] : [] # :nodoc:
|
Encoding::UTF_32BE, Encoding::UTF_32LE] : [] # :nodoc:
|
||||||
|
|
||||||
# Encode given +str+ to URL-encoded form data.
|
# Encodes given +str+ to URL-encoded form data.
|
||||||
#
|
#
|
||||||
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
|
# This method doesn't convert *, -, ., 0-9, A-Z, _, a-z, but does convert SP
|
||||||
# (ASCII space) to + and converts others to %XX.
|
# (ASCII space) to + and converts others to %XX.
|
||||||
|
@ -368,9 +365,9 @@ module URI
|
||||||
# If +enc+ is given, convert +str+ to the encoding before percent encoding.
|
# If +enc+ is given, convert +str+ to the encoding before percent encoding.
|
||||||
#
|
#
|
||||||
# This is an implementation of
|
# This is an implementation of
|
||||||
# http://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data
|
# http://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data.
|
||||||
#
|
#
|
||||||
# See URI.decode_www_form_component, URI.encode_www_form
|
# See URI.decode_www_form_component, URI.encode_www_form.
|
||||||
def self.encode_www_form_component(str, enc=nil)
|
def self.encode_www_form_component(str, enc=nil)
|
||||||
str = str.to_s.dup
|
str = str.to_s.dup
|
||||||
if str.encoding != Encoding::ASCII_8BIT
|
if str.encoding != Encoding::ASCII_8BIT
|
||||||
|
@ -384,17 +381,17 @@ module URI
|
||||||
str.force_encoding(Encoding::US_ASCII)
|
str.force_encoding(Encoding::US_ASCII)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Decode given +str+ of URL-encoded form data.
|
# Decodes given +str+ of URL-encoded form data.
|
||||||
#
|
#
|
||||||
# This decodes + to SP.
|
# This decodes + to SP.
|
||||||
#
|
#
|
||||||
# See URI.encode_www_form_component, URI.decode_www_form
|
# See URI.encode_www_form_component, URI.decode_www_form.
|
||||||
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
|
||||||
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
|
raise ArgumentError, "invalid %-encoding (#{str})" if /%(?!\h\h)/ =~ str
|
||||||
str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
|
str.b.gsub(/\+|%\h\h/, TBLDECWWWCOMP_).force_encoding(enc)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate URL-encoded form data from given +enum+.
|
# Generates URL-encoded form data from given +enum+.
|
||||||
#
|
#
|
||||||
# This generates application/x-www-form-urlencoded data defined in HTML5
|
# This generates application/x-www-form-urlencoded data defined in HTML5
|
||||||
# from given an Enumerable object.
|
# from given an Enumerable object.
|
||||||
|
@ -402,7 +399,7 @@ module URI
|
||||||
# This internally uses URI.encode_www_form_component(str).
|
# This internally uses URI.encode_www_form_component(str).
|
||||||
#
|
#
|
||||||
# This method doesn't convert the encoding of given items, so convert them
|
# This method doesn't convert the encoding of given items, so convert them
|
||||||
# before call this method if you want to send data as other than original
|
# before calling this method if you want to send data as other than original
|
||||||
# encoding or mixed encoding data. (Strings which are encoded in an HTML5
|
# encoding or mixed encoding data. (Strings which are encoded in an HTML5
|
||||||
# ASCII incompatible encoding are converted to UTF-8.)
|
# ASCII incompatible encoding are converted to UTF-8.)
|
||||||
#
|
#
|
||||||
|
@ -420,7 +417,7 @@ module URI
|
||||||
# URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]])
|
# URI.encode_www_form([["q", "ruby"], ["q", "perl"], ["lang", "en"]])
|
||||||
# #=> "q=ruby&q=perl&lang=en"
|
# #=> "q=ruby&q=perl&lang=en"
|
||||||
#
|
#
|
||||||
# See URI.encode_www_form_component, URI.decode_www_form
|
# See URI.encode_www_form_component, URI.decode_www_form.
|
||||||
def self.encode_www_form(enum, enc=nil)
|
def self.encode_www_form(enum, enc=nil)
|
||||||
enum.map do |k,v|
|
enum.map do |k,v|
|
||||||
if v.nil?
|
if v.nil?
|
||||||
|
@ -441,22 +438,22 @@ module URI
|
||||||
end.join('&')
|
end.join('&')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Decode URL-encoded form data from given +str+.
|
# Decodes URL-encoded form data from given +str+.
|
||||||
#
|
#
|
||||||
# This decodes application/x-www-form-urlencoded data
|
# This decodes application/x-www-form-urlencoded data
|
||||||
# and returns array of key-value array.
|
# and returns an array of key-value arrays.
|
||||||
#
|
#
|
||||||
# This refers http://url.spec.whatwg.org/#concept-urlencoded-parser ,
|
# This refers http://url.spec.whatwg.org/#concept-urlencoded-parser,
|
||||||
# so this supports only &-separator, don't support ;-separator.
|
# so this supports only &-separator, and doesn't support ;-separator.
|
||||||
#
|
#
|
||||||
# ary = URI.decode_www_form("a=1&a=2&b=3")
|
# ary = URI.decode_www_form("a=1&a=2&b=3")
|
||||||
# p ary #=> [['a', '1'], ['a', '2'], ['b', '3']]
|
# ary #=> [['a', '1'], ['a', '2'], ['b', '3']]
|
||||||
# p ary.assoc('a').last #=> '1'
|
# ary.assoc('a').last #=> '1'
|
||||||
# p ary.assoc('b').last #=> '3'
|
# ary.assoc('b').last #=> '3'
|
||||||
# p ary.rassoc('a').last #=> '2'
|
# ary.rassoc('a').last #=> '2'
|
||||||
# p Hash[ary] # => {"a"=>"2", "b"=>"3"}
|
# Hash[ary] #=> {"a"=>"2", "b"=>"3"}
|
||||||
#
|
#
|
||||||
# See URI.decode_www_form_component, URI.encode_www_form
|
# See URI.decode_www_form_component, URI.encode_www_form.
|
||||||
def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)
|
def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)
|
||||||
raise ArgumentError, "the input of #{self.name}.#{__method__} must be ASCII only string" unless str.ascii_only?
|
raise ArgumentError, "the input of #{self.name}.#{__method__} must be ASCII only string" unless str.ascii_only?
|
||||||
ary = []
|
ary = []
|
||||||
|
@ -734,7 +731,7 @@ end # module URI
|
||||||
module Kernel
|
module Kernel
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns +uri+ converted to a URI object.
|
# Returns +uri+ converted to an URI object.
|
||||||
#
|
#
|
||||||
def URI(uri)
|
def URI(uri)
|
||||||
if uri.is_a?(URI::Generic)
|
if uri.is_a?(URI::Generic)
|
||||||
|
|
|
@ -49,9 +49,9 @@ module URI
|
||||||
super(tmp)
|
super(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
# protected setter for the host component +v+
|
# Protected setter for the host component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.host=
|
# See also URI::Generic.host=.
|
||||||
#
|
#
|
||||||
def set_host(v)
|
def set_host(v)
|
||||||
v = "" if v.nil? || v == "localhost"
|
v = "" if v.nil? || v == "localhost"
|
||||||
|
|
|
@ -21,11 +21,11 @@ module URI
|
||||||
# http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
|
# http://tools.ietf.org/html/draft-hoffman-ftp-uri-04
|
||||||
#
|
#
|
||||||
class FTP < Generic
|
class FTP < Generic
|
||||||
# A Default port of 21 for URI::FTP
|
# A Default port of 21 for URI::FTP.
|
||||||
DEFAULT_PORT = 21
|
DEFAULT_PORT = 21
|
||||||
|
|
||||||
#
|
#
|
||||||
# An Array of the available components for URI::FTP
|
# An Array of the available components for URI::FTP.
|
||||||
#
|
#
|
||||||
COMPONENT = [
|
COMPONENT = [
|
||||||
:scheme,
|
:scheme,
|
||||||
|
@ -34,7 +34,7 @@ module URI
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
#
|
#
|
||||||
# Typecode is "a", "i" or "d".
|
# Typecode is "a", "i", or "d".
|
||||||
#
|
#
|
||||||
# * "a" indicates a text file (the FTP command was ASCII)
|
# * "a" indicates a text file (the FTP command was ASCII)
|
||||||
# * "i" indicates a binary file (FTP command IMAGE)
|
# * "i" indicates a binary file (FTP command IMAGE)
|
||||||
|
@ -42,8 +42,7 @@ module URI
|
||||||
#
|
#
|
||||||
TYPECODE = ['a', 'i', 'd'].freeze
|
TYPECODE = ['a', 'i', 'd'].freeze
|
||||||
|
|
||||||
# Typecode prefix
|
# Typecode prefix ";type=".
|
||||||
# ';type='
|
|
||||||
TYPECODE_PREFIX = ';type='.freeze
|
TYPECODE_PREFIX = ';type='.freeze
|
||||||
|
|
||||||
def self.new2(user, password, host, port, path,
|
def self.new2(user, password, host, port, path,
|
||||||
|
@ -71,27 +70,29 @@ module URI
|
||||||
#
|
#
|
||||||
# Creates a new URI::FTP object from components, with syntax checking.
|
# Creates a new URI::FTP object from components, with syntax checking.
|
||||||
#
|
#
|
||||||
# The components accepted are +userinfo+, +host+, +port+, +path+ and
|
# The components accepted are +userinfo+, +host+, +port+, +path+, and
|
||||||
# +typecode+.
|
# +typecode+.
|
||||||
#
|
#
|
||||||
# The components should be provided either as an Array, or as a Hash
|
# The components should be provided either as an Array, or as a Hash
|
||||||
# with keys formed by preceding the component names with a colon.
|
# with keys formed by preceding the component names with a colon.
|
||||||
#
|
#
|
||||||
# If an Array is used, the components must be passed in the order
|
# If an Array is used, the components must be passed in the
|
||||||
# [userinfo, host, port, path, typecode]
|
# order <code>[userinfo, host, port, path, typecode]</code>.
|
||||||
#
|
#
|
||||||
# If the path supplied is absolute, it will be escaped in order to
|
# If the path supplied is absolute, it will be escaped in order to
|
||||||
# make it absolute in the URI. Examples:
|
# make it absolute in the URI.
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI::FTP.build(['user:password', 'ftp.example.com', nil,
|
# uri1 = URI::FTP.build(['user:password', 'ftp.example.com', nil,
|
||||||
# '/path/file.zip', 'i'])
|
# '/path/file.zip', 'i'])
|
||||||
# puts uri.to_s -> ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i
|
# uri1.to_s # => "ftp://user:password@ftp.example.com/%2Fpath/file.zip;type=i"
|
||||||
#
|
#
|
||||||
# uri2 = URI::FTP.build({:host => 'ftp.example.com',
|
# uri2 = URI::FTP.build({:host => 'ftp.example.com',
|
||||||
# :path => 'ruby/src'})
|
# :path => 'ruby/src'})
|
||||||
# puts uri2.to_s -> ftp://ftp.example.com/ruby/src
|
# uri2.to_s # => "ftp://ftp.example.com/ruby/src"
|
||||||
#
|
#
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ module URI
|
||||||
# required by RFC1738; instead it is treated as per RFC2396.
|
# required by RFC1738; instead it is treated as per RFC2396.
|
||||||
#
|
#
|
||||||
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
|
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
|
||||||
# +opaque+, +query+ and +fragment+, in that order.
|
# +opaque+, +query+, and +fragment+, in that order.
|
||||||
#
|
#
|
||||||
def initialize(scheme,
|
def initialize(scheme,
|
||||||
userinfo, host, port, registry,
|
userinfo, host, port, registry,
|
||||||
|
@ -155,13 +156,13 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# typecode accessor
|
# typecode accessor.
|
||||||
#
|
#
|
||||||
# see URI::FTP::COMPONENT
|
# See URI::FTP::COMPONENT.
|
||||||
attr_reader :typecode
|
attr_reader :typecode
|
||||||
|
|
||||||
# validates typecode +v+,
|
# Validates typecode +v+,
|
||||||
# returns a +true+ or +false+ boolean
|
# returns +true+ or +false+.
|
||||||
#
|
#
|
||||||
def check_typecode(v)
|
def check_typecode(v)
|
||||||
if TYPECODE.include?(v)
|
if TYPECODE.include?(v)
|
||||||
|
@ -173,9 +174,9 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_typecode
|
private :check_typecode
|
||||||
|
|
||||||
# Private setter for the typecode +v+
|
# Private setter for the typecode +v+.
|
||||||
#
|
#
|
||||||
# see also URI::FTP.typecode=
|
# See also URI::FTP.typecode=.
|
||||||
#
|
#
|
||||||
def set_typecode(v)
|
def set_typecode(v)
|
||||||
@typecode = v
|
@typecode = v
|
||||||
|
@ -190,21 +191,20 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the typecode +v+.
|
# Public setter for the typecode +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::FTP.check_typecode
|
# See also URI::FTP.check_typecode.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse("ftp://john@ftp.example.com/my_file.img")
|
# uri = URI.parse("ftp://john@ftp.example.com/my_file.img")
|
||||||
# #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img>
|
# #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img>
|
||||||
# uri.typecode = "i"
|
# uri.typecode = "i"
|
||||||
# # => "i"
|
|
||||||
# uri
|
# uri
|
||||||
# #=> #<URI::FTP:0x00000000923650 URL:ftp://john@ftp.example.com/my_file.img;type=i>
|
# #=> #<URI::FTP ftp://john@ftp.example.com/my_file.img;type=i>
|
||||||
#
|
#
|
||||||
def typecode=(typecode)
|
def typecode=(typecode)
|
||||||
check_typecode(typecode)
|
check_typecode(typecode)
|
||||||
|
@ -226,29 +226,29 @@ module URI
|
||||||
# RFC 1738 specifically states that the path for an FTP URI does not
|
# RFC 1738 specifically states that the path for an FTP URI does not
|
||||||
# include the / which separates the URI path from the URI host. Example:
|
# include the / which separates the URI path from the URI host. Example:
|
||||||
#
|
#
|
||||||
# +ftp://ftp.example.com/pub/ruby+
|
# <code>ftp://ftp.example.com/pub/ruby</code>
|
||||||
#
|
#
|
||||||
# The above URI indicates that the client should connect to
|
# The above URI indicates that the client should connect to
|
||||||
# ftp.example.com then cd pub/ruby from the initial login directory.
|
# ftp.example.com then cd to pub/ruby from the initial login directory.
|
||||||
#
|
#
|
||||||
# If you want to cd to an absolute directory, you must include an
|
# If you want to cd to an absolute directory, you must include an
|
||||||
# escaped / (%2F) in the path. Example:
|
# escaped / (%2F) in the path. Example:
|
||||||
#
|
#
|
||||||
# +ftp://ftp.example.com/%2Fpub/ruby+
|
# <code>ftp://ftp.example.com/%2Fpub/ruby</code>
|
||||||
#
|
#
|
||||||
# This method will then return "/pub/ruby"
|
# This method will then return "/pub/ruby".
|
||||||
#
|
#
|
||||||
def path
|
def path
|
||||||
return @path.sub(/^\//,'').sub(/^%2F/,'/')
|
return @path.sub(/^\//,'').sub(/^%2F/,'/')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Private setter for the path of the URI::FTP
|
# Private setter for the path of the URI::FTP.
|
||||||
def set_path(v)
|
def set_path(v)
|
||||||
super("/" + v.sub(/^\//, "%2F"))
|
super("/" + v.sub(/^\//, "%2F"))
|
||||||
end
|
end
|
||||||
protected :set_path
|
protected :set_path
|
||||||
|
|
||||||
# Returns a String representation of the URI::FTP
|
# Returns a String representation of the URI::FTP.
|
||||||
def to_s
|
def to_s
|
||||||
save_path = nil
|
save_path = nil
|
||||||
if @typecode
|
if @typecode
|
||||||
|
|
|
@ -23,26 +23,26 @@ module URI
|
||||||
include URI
|
include URI
|
||||||
|
|
||||||
#
|
#
|
||||||
# A Default port of nil for URI::Generic
|
# A Default port of nil for URI::Generic.
|
||||||
#
|
#
|
||||||
DEFAULT_PORT = nil
|
DEFAULT_PORT = nil
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns default port
|
# Returns default port.
|
||||||
#
|
#
|
||||||
def self.default_port
|
def self.default_port
|
||||||
self::DEFAULT_PORT
|
self::DEFAULT_PORT
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns default port
|
# Returns default port.
|
||||||
#
|
#
|
||||||
def default_port
|
def default_port
|
||||||
self.class.default_port
|
self.class.default_port
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# An Array of the available components for URI::Generic
|
# An Array of the available components for URI::Generic.
|
||||||
#
|
#
|
||||||
COMPONENT = [
|
COMPONENT = [
|
||||||
:scheme,
|
:scheme,
|
||||||
|
@ -68,14 +68,13 @@ module URI
|
||||||
#
|
#
|
||||||
# == Synopsis
|
# == Synopsis
|
||||||
#
|
#
|
||||||
# See #new
|
# See ::new.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# At first, tries to create a new URI::Generic instance using
|
# At first, tries to create a new URI::Generic instance using
|
||||||
# URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
|
# URI::Generic::build. But, if exception URI::InvalidComponentError is raised,
|
||||||
# then it URI::Escape.escape all URI components and tries again.
|
# then it does URI::Escape.escape all URI components and tries again.
|
||||||
#
|
|
||||||
#
|
#
|
||||||
def self.build2(args)
|
def self.build2(args)
|
||||||
begin
|
begin
|
||||||
|
@ -106,14 +105,14 @@ module URI
|
||||||
#
|
#
|
||||||
# == Synopsis
|
# == Synopsis
|
||||||
#
|
#
|
||||||
# See #new
|
# See ::new.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Creates a new URI::Generic instance from components of URI::Generic
|
# Creates a new URI::Generic instance from components of URI::Generic
|
||||||
# with check. Components are: scheme, userinfo, host, port, registry, path,
|
# with check. Components are: scheme, userinfo, host, port, registry, path,
|
||||||
# opaque, query and fragment. You can provide arguments either by an Array or a Hash.
|
# opaque, query, and fragment. You can provide arguments either by an Array or a Hash.
|
||||||
# See #new for hash keys to use or for order of array items.
|
# See ::new for hash keys to use or for order of array items.
|
||||||
#
|
#
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
if args.kind_of?(Array) &&
|
if args.kind_of?(Array) &&
|
||||||
|
@ -137,31 +136,32 @@ module URI
|
||||||
tmp << true
|
tmp << true
|
||||||
return self.new(*tmp)
|
return self.new(*tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# == Args
|
# == Args
|
||||||
#
|
#
|
||||||
# +scheme+::
|
# +scheme+::
|
||||||
# Protocol scheme, i.e. 'http','ftp','mailto' and so on.
|
# Protocol scheme, i.e. 'http','ftp','mailto' and so on.
|
||||||
# +userinfo+::
|
# +userinfo+::
|
||||||
# User name and password, i.e. 'sdmitry:bla'
|
# User name and password, i.e. 'sdmitry:bla'.
|
||||||
# +host+::
|
# +host+::
|
||||||
# Server host name
|
# Server host name.
|
||||||
# +port+::
|
# +port+::
|
||||||
# Server port
|
# Server port.
|
||||||
# +registry+::
|
# +registry+::
|
||||||
# Registry of naming authorities.
|
# Registry of naming authorities.
|
||||||
# +path+::
|
# +path+::
|
||||||
# Path on server
|
# Path on server.
|
||||||
# +opaque+::
|
# +opaque+::
|
||||||
# Opaque part
|
# Opaque part.
|
||||||
# +query+::
|
# +query+::
|
||||||
# Query data
|
# Query data.
|
||||||
# +fragment+::
|
# +fragment+::
|
||||||
# A part of URI after '#' sign
|
# Part of the URI after '#' character.
|
||||||
# +parser+::
|
# +parser+::
|
||||||
# Parser for internal use [URI::DEFAULT_PARSER by default]
|
# Parser for internal use [URI::DEFAULT_PARSER by default].
|
||||||
# +arg_check+::
|
# +arg_check+::
|
||||||
# Check arguments [false by default]
|
# Check arguments [false by default].
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
|
@ -215,38 +215,37 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# returns the scheme component of the URI.
|
# Returns the scheme component of the URI.
|
||||||
#
|
#
|
||||||
# URI("http://foo/bar/baz").scheme #=> "http"
|
# URI("http://foo/bar/baz").scheme #=> "http"
|
||||||
#
|
#
|
||||||
attr_reader :scheme
|
attr_reader :scheme
|
||||||
|
|
||||||
# returns the host component of the URI.
|
# Returns the host component of the URI.
|
||||||
#
|
#
|
||||||
# URI("http://foo/bar/baz").host #=> "foo"
|
# URI("http://foo/bar/baz").host #=> "foo"
|
||||||
#
|
#
|
||||||
# It returns nil if no host component.
|
# It returns nil if no host component exists.
|
||||||
#
|
#
|
||||||
# URI("mailto:foo@example.org").host #=> nil
|
# URI("mailto:foo@example.org").host #=> nil
|
||||||
#
|
#
|
||||||
# The component doesn't contains the port number.
|
# The component does not contain the port number.
|
||||||
#
|
#
|
||||||
# URI("http://foo:8080/bar/baz").host #=> "foo"
|
# URI("http://foo:8080/bar/baz").host #=> "foo"
|
||||||
#
|
#
|
||||||
# Since IPv6 addresses are wrapped by brackets in URIs,
|
# Since IPv6 addresses are wrapped with brackets in URIs,
|
||||||
# this method returns IPv6 addresses wrapped by brackets.
|
# this method returns IPv6 addresses wrapped with brackets.
|
||||||
# This form is not appropriate to pass socket methods such as TCPSocket.open.
|
# This form is not appropriate to pass to socket methods such as TCPSocket.open.
|
||||||
# If unwrapped host names are required, use "hostname" method.
|
# If unwrapped host names are required, use the #hostname method.
|
||||||
#
|
#
|
||||||
# URI("http://[::1]/bar/baz").host #=> "[::1]"
|
# URI("http://[::1]/bar/baz").host #=> "[::1]"
|
||||||
# URI("http://[::1]/bar/baz").hostname #=> "::1"
|
# URI("http://[::1]/bar/baz").hostname #=> "::1"
|
||||||
#
|
#
|
||||||
attr_reader :host
|
attr_reader :host
|
||||||
|
|
||||||
# returns the port component of the URI.
|
# Returns the port component of the URI.
|
||||||
#
|
|
||||||
# URI("http://foo/bar/baz").port #=> "80"
|
|
||||||
#
|
#
|
||||||
|
# URI("http://foo/bar/baz").port #=> "80"
|
||||||
# URI("http://foo:8080/bar/baz").port #=> "8080"
|
# URI("http://foo:8080/bar/baz").port #=> "8080"
|
||||||
#
|
#
|
||||||
attr_reader :port
|
attr_reader :port
|
||||||
|
@ -255,13 +254,13 @@ module URI
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns the path component of the URI.
|
# Returns the path component of the URI.
|
||||||
#
|
#
|
||||||
# URI("http://foo/bar/baz").path #=> "/bar/baz"
|
# URI("http://foo/bar/baz").path #=> "/bar/baz"
|
||||||
#
|
#
|
||||||
attr_reader :path
|
attr_reader :path
|
||||||
|
|
||||||
# returns the query component of the URI.
|
# Returns the query component of the URI.
|
||||||
#
|
#
|
||||||
# URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
|
# URI("http://foo/bar/baz?search=FooBar").query #=> "search=FooBar"
|
||||||
#
|
#
|
||||||
|
@ -278,15 +277,15 @@ module URI
|
||||||
#
|
#
|
||||||
attr_reader :opaque
|
attr_reader :opaque
|
||||||
|
|
||||||
# returns the fragment component of the URI.
|
# Returns the fragment component of the URI.
|
||||||
#
|
#
|
||||||
# URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
|
# URI("http://foo/bar/baz?search=FooBar#ponies").fragment #=> "ponies"
|
||||||
#
|
#
|
||||||
attr_reader :fragment
|
attr_reader :fragment
|
||||||
|
|
||||||
# returns the parser to be used.
|
# Returns the parser to be used.
|
||||||
#
|
#
|
||||||
# Unless a URI::Parser is defined, then DEFAULT_PARSER is used.
|
# Unless a URI::Parser is defined, DEFAULT_PARSER is used.
|
||||||
#
|
#
|
||||||
def parser
|
def parser
|
||||||
if !defined?(@parser) || !@parser
|
if !defined?(@parser) || !@parser
|
||||||
|
@ -296,7 +295,8 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# replace self by other URI object
|
# Replaces self by other URI object.
|
||||||
|
#
|
||||||
def replace!(oth)
|
def replace!(oth)
|
||||||
if self.class != oth.class
|
if self.class != oth.class
|
||||||
raise ArgumentError, "expected #{self.class} object"
|
raise ArgumentError, "expected #{self.class} object"
|
||||||
|
@ -316,7 +316,7 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the scheme +v+ component against the URI::Parser Regexp for :SCHEME
|
# Checks the scheme +v+ component against the URI::Parser Regexp for :SCHEME.
|
||||||
#
|
#
|
||||||
def check_scheme(v)
|
def check_scheme(v)
|
||||||
if v && parser.regexp[:SCHEME] !~ v
|
if v && parser.regexp[:SCHEME] !~ v
|
||||||
|
@ -328,9 +328,9 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_scheme
|
private :check_scheme
|
||||||
|
|
||||||
# protected setter for the scheme component +v+
|
# Protected setter for the scheme component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.scheme=
|
# See also URI::Generic.scheme=.
|
||||||
#
|
#
|
||||||
def set_scheme(v)
|
def set_scheme(v)
|
||||||
@scheme = v&.downcase
|
@scheme = v&.downcase
|
||||||
|
@ -345,10 +345,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the scheme component +v+.
|
# Public setter for the scheme component +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_scheme
|
# See also URI::Generic.check_scheme.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -356,9 +356,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com")
|
# uri = URI.parse("http://my.example.com")
|
||||||
# uri.scheme = "https"
|
# uri.scheme = "https"
|
||||||
# # => "https"
|
# uri.to_s #=> "https://my.example.com"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x000000008e89e8 URL:https://my.example.com>
|
|
||||||
#
|
#
|
||||||
def scheme=(v)
|
def scheme=(v)
|
||||||
check_scheme(v)
|
check_scheme(v)
|
||||||
|
@ -367,13 +365,13 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the +user+ and +password+.
|
# Checks the +user+ and +password+.
|
||||||
#
|
#
|
||||||
# If +password+ is not provided, then +user+ is
|
# If +password+ is not provided, then +user+ is
|
||||||
# split, using URI::Generic.split_userinfo, to
|
# split, using URI::Generic.split_userinfo, to
|
||||||
# pull +user+ and +password.
|
# pull +user+ and +password.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_user, URI::Generic.check_password
|
# See also URI::Generic.check_user, URI::Generic.check_password.
|
||||||
#
|
#
|
||||||
def check_userinfo(user, password = nil)
|
def check_userinfo(user, password = nil)
|
||||||
if !password
|
if !password
|
||||||
|
@ -387,8 +385,8 @@ module URI
|
||||||
private :check_userinfo
|
private :check_userinfo
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the user +v+ component for RFC2396 compliance
|
# Checks the user +v+ component for RFC2396 compliance
|
||||||
# and against the URI::Parser Regexp for :USERINFO
|
# and against the URI::Parser Regexp for :USERINFO.
|
||||||
#
|
#
|
||||||
# Can not have a registry or opaque component defined,
|
# Can not have a registry or opaque component defined,
|
||||||
# with a user component defined.
|
# with a user component defined.
|
||||||
|
@ -411,8 +409,8 @@ module URI
|
||||||
private :check_user
|
private :check_user
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the password +v+ component for RFC2396 compliance
|
# Checks the password +v+ component for RFC2396 compliance
|
||||||
# and against the URI::Parser Regexp for :USERINFO
|
# and against the URI::Parser Regexp for :USERINFO.
|
||||||
#
|
#
|
||||||
# Can not have a registry or opaque component defined,
|
# Can not have a registry or opaque component defined,
|
||||||
# with a user component defined.
|
# with a user component defined.
|
||||||
|
@ -439,7 +437,7 @@ module URI
|
||||||
private :check_password
|
private :check_password
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sets userinfo, argument is string like 'name:pass'
|
# Sets userinfo, argument is string like 'name:pass'.
|
||||||
#
|
#
|
||||||
def userinfo=(userinfo)
|
def userinfo=(userinfo)
|
||||||
if userinfo.nil?
|
if userinfo.nil?
|
||||||
|
@ -458,10 +456,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the +user+ component.
|
# Public setter for the +user+ component
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_user
|
# See also URI::Generic.check_user.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -469,9 +467,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://john:S3nsit1ve@my.example.com")
|
# uri = URI.parse("http://john:S3nsit1ve@my.example.com")
|
||||||
# uri.user = "sam"
|
# uri.user = "sam"
|
||||||
# # => "sam"
|
# uri.to_s #=> "http://sam:V3ry_S3nsit1ve@my.example.com"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x00000000881d90 URL:http://sam:V3ry_S3nsit1ve@my.example.com>
|
|
||||||
#
|
#
|
||||||
def user=(user)
|
def user=(user)
|
||||||
check_user(user)
|
check_user(user)
|
||||||
|
@ -487,10 +483,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the +password+ component.
|
# Public setter for the +password+ component
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_password
|
# See also URI::Generic.check_password.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -498,9 +494,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://john:S3nsit1ve@my.example.com")
|
# uri = URI.parse("http://john:S3nsit1ve@my.example.com")
|
||||||
# uri.password = "V3ry_S3nsit1ve"
|
# uri.password = "V3ry_S3nsit1ve"
|
||||||
# # => "V3ry_S3nsit1ve"
|
# uri.to_s #=> "http://john:V3ry_S3nsit1ve@my.example.com"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x00000000881d90 URL:http://john:V3ry_S3nsit1ve@my.example.com>
|
|
||||||
#
|
#
|
||||||
def password=(password)
|
def password=(password)
|
||||||
check_password(password)
|
check_password(password)
|
||||||
|
@ -508,10 +502,10 @@ module URI
|
||||||
# returns password
|
# returns password
|
||||||
end
|
end
|
||||||
|
|
||||||
# protect setter for the +user+ component, and +password+ if available.
|
# Protected setter for the +user+ component, and +password+ if available
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.userinfo=
|
# See also URI::Generic.userinfo=.
|
||||||
#
|
#
|
||||||
def set_userinfo(user, password = nil)
|
def set_userinfo(user, password = nil)
|
||||||
unless password
|
unless password
|
||||||
|
@ -524,9 +518,9 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_userinfo
|
protected :set_userinfo
|
||||||
|
|
||||||
# protected setter for the user component +v+
|
# Protected setter for the user component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.user=
|
# See also URI::Generic.user=.
|
||||||
#
|
#
|
||||||
def set_user(v)
|
def set_user(v)
|
||||||
set_userinfo(v, @password)
|
set_userinfo(v, @password)
|
||||||
|
@ -534,9 +528,9 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_user
|
protected :set_user
|
||||||
|
|
||||||
# protected setter for the password component +v+
|
# Protected setter for the password component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.password=
|
# See also URI::Generic.password=.
|
||||||
#
|
#
|
||||||
def set_password(v)
|
def set_password(v)
|
||||||
@password = v
|
@password = v
|
||||||
|
@ -544,8 +538,8 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_password
|
protected :set_password
|
||||||
|
|
||||||
# returns the userinfo +ui+ as user, password
|
# Returns the userinfo +ui+ as <code>[user, password]</code>
|
||||||
# if properly formatted as 'user:password'
|
# if properly formatted as 'user:password'.
|
||||||
def split_userinfo(ui)
|
def split_userinfo(ui)
|
||||||
return nil, nil unless ui
|
return nil, nil unless ui
|
||||||
user, password = ui.split(':', 2)
|
user, password = ui.split(':', 2)
|
||||||
|
@ -554,13 +548,13 @@ module URI
|
||||||
end
|
end
|
||||||
private :split_userinfo
|
private :split_userinfo
|
||||||
|
|
||||||
# escapes 'user:password' +v+ based on RFC 1738 section 3.1
|
# Escapes 'user:password' +v+ based on RFC 1738 section 3.1.
|
||||||
def escape_userpass(v)
|
def escape_userpass(v)
|
||||||
parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/
|
parser.escape(v, /[@:\/]/o) # RFC 1738 section 3.1 #/
|
||||||
end
|
end
|
||||||
private :escape_userpass
|
private :escape_userpass
|
||||||
|
|
||||||
# returns the userinfo, either as 'user' or 'user:password'
|
# Returns the userinfo, either as 'user' or 'user:password'.
|
||||||
def userinfo
|
def userinfo
|
||||||
if @user.nil?
|
if @user.nil?
|
||||||
nil
|
nil
|
||||||
|
@ -571,19 +565,19 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns the user component
|
# Returns the user component.
|
||||||
def user
|
def user
|
||||||
@user
|
@user
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns the password component
|
# Returns the password component.
|
||||||
def password
|
def password
|
||||||
@password
|
@password
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the host +v+ component for RFC2396 compliance
|
# Checks the host +v+ component for RFC2396 compliance
|
||||||
# and against the URI::Parser Regexp for :HOST
|
# and against the URI::Parser Regexp for :HOST.
|
||||||
#
|
#
|
||||||
# Can not have a registry or opaque component defined,
|
# Can not have a registry or opaque component defined,
|
||||||
# with a host component defined.
|
# with a host component defined.
|
||||||
|
@ -603,9 +597,9 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_host
|
private :check_host
|
||||||
|
|
||||||
# protected setter for the host component +v+
|
# Protected setter for the host component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.host=
|
# See also URI::Generic.host=.
|
||||||
#
|
#
|
||||||
def set_host(v)
|
def set_host(v)
|
||||||
@host = v
|
@host = v
|
||||||
|
@ -620,10 +614,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the host component +v+.
|
# Public setter for the host component +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_host
|
# See also URI::Generic.check_host.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -631,9 +625,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com")
|
# uri = URI.parse("http://my.example.com")
|
||||||
# uri.host = "foo.com"
|
# uri.host = "foo.com"
|
||||||
# # => "foo.com"
|
# uri.to_s #=> "http://foo.com"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x000000008e89e8 URL:http://foo.com>
|
|
||||||
#
|
#
|
||||||
def host=(v)
|
def host=(v)
|
||||||
check_host(v)
|
check_host(v)
|
||||||
|
@ -641,32 +633,31 @@ module URI
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
# extract the host part of the URI and unwrap brackets for IPv6 addresses.
|
# Extract the host part of the URI and unwrap brackets for IPv6 addresses.
|
||||||
#
|
#
|
||||||
# This method is same as URI::Generic#host except
|
# This method is the same as URI::Generic#host except
|
||||||
# brackets for IPv6 (and future IP) addresses are removed.
|
# brackets for IPv6 (and future IP) addresses are removed.
|
||||||
#
|
#
|
||||||
# u = URI("http://[::1]/bar")
|
# uri = URI("http://[::1]/bar")
|
||||||
# p u.hostname #=> "::1"
|
# uri.hostname #=> "::1"
|
||||||
# p u.host #=> "[::1]"
|
# uri.host #=> "[::1]"
|
||||||
#
|
#
|
||||||
def hostname
|
def hostname
|
||||||
v = self.host
|
v = self.host
|
||||||
/\A\[(.*)\]\z/ =~ v ? $1 : v
|
/\A\[(.*)\]\z/ =~ v ? $1 : v
|
||||||
end
|
end
|
||||||
|
|
||||||
# set the host part of the URI as the argument with brackets for IPv6 addresses.
|
# Sets the host part of the URI as the argument with brackets for IPv6 addresses.
|
||||||
#
|
#
|
||||||
# This method is same as URI::Generic#host= except
|
# This method is the same as URI::Generic#host= except
|
||||||
# the argument can be bare IPv6 address.
|
# the argument can be a bare IPv6 address.
|
||||||
#
|
#
|
||||||
# u = URI("http://foo/bar")
|
# uri = URI("http://foo/bar")
|
||||||
# p u.to_s #=> "http://foo/bar"
|
# uri.hostname = "::1"
|
||||||
# u.hostname = "::1"
|
# uri.to_s #=> "http://[::1]/bar"
|
||||||
# p u.to_s #=> "http://[::1]/bar"
|
|
||||||
#
|
#
|
||||||
# If the argument seems IPv6 address,
|
# If the argument seems to be an IPv6 address,
|
||||||
# it is wrapped by brackets.
|
# it is wrapped with brackets.
|
||||||
#
|
#
|
||||||
def hostname=(v)
|
def hostname=(v)
|
||||||
v = "[#{v}]" if /\A\[.*\]\z/ !~ v && /:/ =~ v
|
v = "[#{v}]" if /\A\[.*\]\z/ !~ v && /:/ =~ v
|
||||||
|
@ -674,8 +665,8 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the port +v+ component for RFC2396 compliance
|
# Checks the port +v+ component for RFC2396 compliance
|
||||||
# and against the URI::Parser Regexp for :PORT
|
# and against the URI::Parser Regexp for :PORT.
|
||||||
#
|
#
|
||||||
# Can not have a registry or opaque component defined,
|
# Can not have a registry or opaque component defined,
|
||||||
# with a port component defined.
|
# with a port component defined.
|
||||||
|
@ -695,9 +686,9 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_port
|
private :check_port
|
||||||
|
|
||||||
# protected setter for the port component +v+
|
# Protected setter for the port component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.port=
|
# See also URI::Generic.port=.
|
||||||
#
|
#
|
||||||
def set_port(v)
|
def set_port(v)
|
||||||
v = v.empty? ? nil : v.to_i unless !v || v.kind_of?(Integer)
|
v = v.empty? ? nil : v.to_i unless !v || v.kind_of?(Integer)
|
||||||
|
@ -713,10 +704,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the port component +v+.
|
# Public setter for the port component +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_port
|
# See also URI::Generic.check_port.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -724,9 +715,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com")
|
# uri = URI.parse("http://my.example.com")
|
||||||
# uri.port = 8080
|
# uri.port = 8080
|
||||||
# # => 8080
|
# uri.to_s #=> "http://my.example.com:8080"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com:8080>
|
|
||||||
#
|
#
|
||||||
def port=(v)
|
def port=(v)
|
||||||
check_port(v)
|
check_port(v)
|
||||||
|
@ -749,9 +738,9 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the path +v+ component for RFC2396 compliance
|
# Checks the path +v+ component for RFC2396 compliance
|
||||||
# and against the URI::Parser Regexp
|
# and against the URI::Parser Regexp
|
||||||
# for :ABS_PATH and :REL_PATH
|
# for :ABS_PATH and :REL_PATH.
|
||||||
#
|
#
|
||||||
# Can not have a opaque component defined,
|
# Can not have a opaque component defined,
|
||||||
# with a path component defined.
|
# with a path component defined.
|
||||||
|
@ -784,9 +773,9 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_path
|
private :check_path
|
||||||
|
|
||||||
# protected setter for the path component +v+
|
# Protected setter for the path component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.path=
|
# See also URI::Generic.path=.
|
||||||
#
|
#
|
||||||
def set_path(v)
|
def set_path(v)
|
||||||
@path = v
|
@path = v
|
||||||
|
@ -801,10 +790,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the path component +v+.
|
# Public setter for the path component +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_path
|
# See also URI::Generic.check_path.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -812,9 +801,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com/pub/files")
|
# uri = URI.parse("http://my.example.com/pub/files")
|
||||||
# uri.path = "/faq/"
|
# uri.path = "/faq/"
|
||||||
# # => "/faq/"
|
# uri.to_s #=> "http://my.example.com/faq/"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/faq/>
|
|
||||||
#
|
#
|
||||||
def path=(v)
|
def path=(v)
|
||||||
check_path(v)
|
check_path(v)
|
||||||
|
@ -830,7 +817,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the query component +v+.
|
# Public setter for the query component +v+.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -838,9 +825,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com/?id=25")
|
# uri = URI.parse("http://my.example.com/?id=25")
|
||||||
# uri.query = "id=1"
|
# uri.query = "id=1"
|
||||||
# # => "id=1"
|
# uri.to_s #=> "http://my.example.com/?id=1"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x000000008e89e8 URL:http://my.example.com/?id=1>
|
|
||||||
#
|
#
|
||||||
def query=(v)
|
def query=(v)
|
||||||
return @query = nil unless v
|
return @query = nil unless v
|
||||||
|
@ -857,10 +842,10 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the opaque +v+ component for RFC2396 compliance and
|
# Checks the opaque +v+ component for RFC2396 compliance and
|
||||||
# against the URI::Parser Regexp for :OPAQUE
|
# against the URI::Parser Regexp for :OPAQUE.
|
||||||
#
|
#
|
||||||
# Can not have a host, port, user or path component defined,
|
# Can not have a host, port, user, or path component defined,
|
||||||
# with an opaque component defined.
|
# with an opaque component defined.
|
||||||
#
|
#
|
||||||
def check_opaque(v)
|
def check_opaque(v)
|
||||||
|
@ -881,9 +866,9 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_opaque
|
private :check_opaque
|
||||||
|
|
||||||
# protected setter for the opaque component +v+
|
# Protected setter for the opaque component +v+.
|
||||||
#
|
#
|
||||||
# see also URI::Generic.opaque=
|
# See also URI::Generic.opaque=.
|
||||||
#
|
#
|
||||||
def set_opaque(v)
|
def set_opaque(v)
|
||||||
@opaque = v
|
@opaque = v
|
||||||
|
@ -898,10 +883,10 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the opaque component +v+.
|
# Public setter for the opaque component +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# see also URI::Generic.check_opaque
|
# See also URI::Generic.check_opaque.
|
||||||
#
|
#
|
||||||
def opaque=(v)
|
def opaque=(v)
|
||||||
check_opaque(v)
|
check_opaque(v)
|
||||||
|
@ -910,7 +895,7 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# check the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT
|
# Checks the fragment +v+ component against the URI::Parser Regexp for :FRAGMENT.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# == Args
|
# == Args
|
||||||
|
@ -920,8 +905,8 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# public setter for the fragment component +v+.
|
# Public setter for the fragment component +v+
|
||||||
# (with validation)
|
# (with validation).
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -929,9 +914,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com/?id=25#time=1305212049")
|
# uri = URI.parse("http://my.example.com/?id=25#time=1305212049")
|
||||||
# uri.fragment = "time=1305212086"
|
# uri.fragment = "time=1305212086"
|
||||||
# # => "time=1305212086"
|
# uri.to_s #=> "http://my.example.com/?id=25#time=1305212086"
|
||||||
# uri
|
|
||||||
# #=> #<URI::HTTP:0x000000007a81f8 URL:http://my.example.com/?id=25#time=1305212086>
|
|
||||||
#
|
#
|
||||||
def fragment=(v)
|
def fragment=(v)
|
||||||
return @fragment = nil unless v
|
return @fragment = nil unless v
|
||||||
|
@ -947,25 +930,23 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns true if URI is hierarchical
|
# Returns true if URI is hierarchical.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# URI has components listed in order of decreasing signficance from left to right
|
# URI has components listed in order of decreasing significance from left to right,
|
||||||
# see RFC3986 https://tools.ietf.org/html/rfc3986 1.2.3
|
# see RFC3986 https://tools.ietf.org/html/rfc3986 1.2.3.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com/")
|
# uri = URI.parse("http://my.example.com/")
|
||||||
# => #<URI::HTTP http://my.example.com/>
|
|
||||||
# uri.hierarchical?
|
# uri.hierarchical?
|
||||||
# # => true
|
# #=> true
|
||||||
# uri = URI.parse("mailto:joe@example.com")
|
# uri = URI.parse("mailto:joe@example.com")
|
||||||
# => #<URI::MailTo mailto:joe@example.com>
|
|
||||||
# uri.hierarchical?
|
# uri.hierarchical?
|
||||||
# # => false
|
# #=> false
|
||||||
#
|
#
|
||||||
def hierarchical?
|
def hierarchical?
|
||||||
if @path
|
if @path
|
||||||
|
@ -976,7 +957,7 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns true if URI has a scheme (e.g. http:// or https://) specified
|
# Returns true if URI has a scheme (e.g. http:// or https://) specified.
|
||||||
#
|
#
|
||||||
def absolute?
|
def absolute?
|
||||||
if @scheme
|
if @scheme
|
||||||
|
@ -988,14 +969,14 @@ module URI
|
||||||
alias absolute absolute?
|
alias absolute absolute?
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns true if URI does not have a scheme (e.g. http:// or https://) specified
|
# Returns true if URI does not have a scheme (e.g. http:// or https://) specified.
|
||||||
#
|
#
|
||||||
def relative?
|
def relative?
|
||||||
!absolute?
|
!absolute?
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# returns an Array of the path split on '/'
|
# Returns an Array of the path split on '/'.
|
||||||
#
|
#
|
||||||
def split_path(path)
|
def split_path(path)
|
||||||
path.split("/", -1)
|
path.split("/", -1)
|
||||||
|
@ -1077,7 +1058,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Destructive form of #merge
|
# Destructive form of #merge.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -1085,8 +1066,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com")
|
# uri = URI.parse("http://my.example.com")
|
||||||
# uri.merge!("/main.rbx?page=1")
|
# uri.merge!("/main.rbx?page=1")
|
||||||
# p uri
|
# uri.to_s # => "http://my.example.com/main.rbx?page=1"
|
||||||
# # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
|
|
||||||
#
|
#
|
||||||
def merge!(oth)
|
def merge!(oth)
|
||||||
t = merge(oth)
|
t = merge(oth)
|
||||||
|
@ -1106,15 +1086,15 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Merges two URI's.
|
# Merges two URIs.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com")
|
# uri = URI.parse("http://my.example.com")
|
||||||
# p uri.merge("/main.rbx?page=1")
|
# uri.merge("/main.rbx?page=1")
|
||||||
# # => #<URI::HTTP:0x2021f3b0 URL:http://my.example.com/main.rbx?page=1>
|
# # => "http://my.example.com/main.rbx?page=1"
|
||||||
#
|
#
|
||||||
def merge(oth)
|
def merge(oth)
|
||||||
rel = parser.send(:convert_to_uri, oth)
|
rel = parser.send(:convert_to_uri, oth)
|
||||||
|
@ -1259,15 +1239,15 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Calculates relative path from oth to self
|
# Calculates relative path from oth to self.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse('http://my.example.com/main.rbx?page=1')
|
# uri = URI.parse('http://my.example.com/main.rbx?page=1')
|
||||||
# p uri.route_from('http://my.example.com')
|
# uri.route_from('http://my.example.com')
|
||||||
# #=> #<URI::Generic:0x20218858 URL:/main.rbx?page=1>
|
# #=> #<URI::Generic /main.rbx?page=1>
|
||||||
#
|
#
|
||||||
def route_from(oth)
|
def route_from(oth)
|
||||||
# you can modify `rel', but can not `oth'.
|
# you can modify `rel', but can not `oth'.
|
||||||
|
@ -1299,15 +1279,15 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Calculates relative path to oth from self
|
# Calculates relative path to oth from self.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse('http://my.example.com')
|
# uri = URI.parse('http://my.example.com')
|
||||||
# p uri.route_to('http://my.example.com/main.rbx?page=1')
|
# uri.route_to('http://my.example.com/main.rbx?page=1')
|
||||||
# #=> #<URI::Generic:0x2020c2f6 URL:/main.rbx?page=1>
|
# #=> #<URI::Generic /main.rbx?page=1>
|
||||||
#
|
#
|
||||||
def route_to(oth)
|
def route_to(oth)
|
||||||
parser.send(:convert_to_uri, oth).route_from(self)
|
parser.send(:convert_to_uri, oth).route_from(self)
|
||||||
|
@ -1333,7 +1313,7 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Destructive version of #normalize
|
# Destructive version of #normalize.
|
||||||
#
|
#
|
||||||
def normalize!
|
def normalize!
|
||||||
if path&.empty?
|
if path&.empty?
|
||||||
|
@ -1348,7 +1328,7 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Constructs String from URI
|
# Constructs String from URI.
|
||||||
#
|
#
|
||||||
def to_s
|
def to_s
|
||||||
str = ''.dup
|
str = ''.dup
|
||||||
|
@ -1388,7 +1368,7 @@ module URI
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Compares two URIs
|
# Compares two URIs.
|
||||||
#
|
#
|
||||||
def ==(oth)
|
def ==(oth)
|
||||||
if self.class == oth.class
|
if self.class == oth.class
|
||||||
|
@ -1421,7 +1401,7 @@ module URI
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
|
||||||
# returns an Array of the components defined from the COMPONENT Array
|
# Returns an Array of the components defined from the COMPONENT Array.
|
||||||
def component_ary
|
def component_ary
|
||||||
component.collect do |x|
|
component.collect do |x|
|
||||||
self.send(x)
|
self.send(x)
|
||||||
|
@ -1432,18 +1412,18 @@ module URI
|
||||||
# == Args
|
# == Args
|
||||||
#
|
#
|
||||||
# +components+::
|
# +components+::
|
||||||
# Multiple Symbol arguments defined in URI::HTTP
|
# Multiple Symbol arguments defined in URI::HTTP.
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Selects specified components from URI
|
# Selects specified components from URI.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# uri = URI.parse('http://myuser:mypass@my.example.com/test.rbx')
|
# uri = URI.parse('http://myuser:mypass@my.example.com/test.rbx')
|
||||||
# p uri.select(:userinfo, :host, :path)
|
# uri.select(:userinfo, :host, :path)
|
||||||
# # => ["myuser:mypass", "my.example.com", "/test.rbx"]
|
# # => ["myuser:mypass", "my.example.com", "/test.rbx"]
|
||||||
#
|
#
|
||||||
def select(*components)
|
def select(*components)
|
||||||
|
@ -1469,8 +1449,8 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# attempts to parse other URI +oth+,
|
# Attempts to parse other URI +oth+,
|
||||||
# returns [parsed_oth, self]
|
# returns [parsed_oth, self].
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
|
@ -1478,7 +1458,7 @@ module URI
|
||||||
#
|
#
|
||||||
# uri = URI.parse("http://my.example.com")
|
# uri = URI.parse("http://my.example.com")
|
||||||
# uri.coerce("http://foo.com")
|
# uri.coerce("http://foo.com")
|
||||||
# #=> [#<URI::HTTP:0x00000000bcb028 URL:http://foo.com/>, #<URI::HTTP:0x00000000d92178 URL:http://my.example.com>]
|
# #=> [#<URI::HTTP http://foo.com>, #<URI::HTTP http://my.example.com>]
|
||||||
#
|
#
|
||||||
def coerce(oth)
|
def coerce(oth)
|
||||||
case oth
|
case oth
|
||||||
|
@ -1491,15 +1471,15 @@ module URI
|
||||||
return oth, self
|
return oth, self
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns a proxy URI.
|
# Returns a proxy URI.
|
||||||
# The proxy URI is obtained from environment variables such as http_proxy,
|
# The proxy URI is obtained from environment variables such as http_proxy,
|
||||||
# ftp_proxy, no_proxy, etc.
|
# ftp_proxy, no_proxy, etc.
|
||||||
# If there is no proper proxy, nil is returned.
|
# If there is no proper proxy, nil is returned.
|
||||||
#
|
#
|
||||||
# If the optional parameter, +env+, is specified, it is used instead of ENV.
|
# If the optional parameter +env+ is specified, it is used instead of ENV.
|
||||||
#
|
#
|
||||||
# Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.)
|
# Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.)
|
||||||
# are examined too.
|
# are examined, too.
|
||||||
#
|
#
|
||||||
# But http_proxy and HTTP_PROXY is treated specially under CGI environment.
|
# But http_proxy and HTTP_PROXY is treated specially under CGI environment.
|
||||||
# It's because HTTP_PROXY may be set by Proxy: header.
|
# It's because HTTP_PROXY may be set by Proxy: header.
|
||||||
|
|
|
@ -21,10 +21,10 @@ module URI
|
||||||
# update. See <URL:http://support.microsoft.com/kb/834489>.
|
# update. See <URL:http://support.microsoft.com/kb/834489>.
|
||||||
#
|
#
|
||||||
class HTTP < Generic
|
class HTTP < Generic
|
||||||
# A Default port of 80 for URI::HTTP
|
# A Default port of 80 for URI::HTTP.
|
||||||
DEFAULT_PORT = 80
|
DEFAULT_PORT = 80
|
||||||
|
|
||||||
# An Array of the available components for URI::HTTP
|
# An Array of the available components for URI::HTTP.
|
||||||
COMPONENT = %i[
|
COMPONENT = %i[
|
||||||
scheme
|
scheme
|
||||||
userinfo host port
|
userinfo host port
|
||||||
|
@ -36,22 +36,22 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Create a new URI::HTTP object from components, with syntax checking.
|
# Creates a new URI::HTTP object from components, with syntax checking.
|
||||||
#
|
#
|
||||||
# The components accepted are userinfo, host, port, path, query and
|
# The components accepted are userinfo, host, port, path, query, and
|
||||||
# fragment.
|
# fragment.
|
||||||
#
|
#
|
||||||
# The components should be provided either as an Array, or as a Hash
|
# The components should be provided either as an Array, or as a Hash
|
||||||
# with keys formed by preceding the component names with a colon.
|
# with keys formed by preceding the component names with a colon.
|
||||||
#
|
#
|
||||||
# If an Array is used, the components must be passed in the order
|
# If an Array is used, the components must be passed in the
|
||||||
# [userinfo, host, port, path, query, fragment].
|
# order <code>[userinfo, host, port, path, query, fragment]</code>.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# newuri = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
|
# uri = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
|
||||||
#
|
#
|
||||||
# newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
|
# uri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
|
||||||
# "query", 'fragment'])
|
# "query", 'fragment'])
|
||||||
#
|
#
|
||||||
# Currently, if passed userinfo components this method generates
|
# Currently, if passed userinfo components this method generates
|
||||||
|
@ -72,8 +72,8 @@ module URI
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# newuri = URI::HTTP.build(path: '/foo/bar', query: 'test=true')
|
# uri = URI::HTTP.build(path: '/foo/bar', query: 'test=true')
|
||||||
# newuri.request_uri # => "/foo/bar?test=true"
|
# uri.request_uri # => "/foo/bar?test=true"
|
||||||
#
|
#
|
||||||
def request_uri
|
def request_uri
|
||||||
return unless @path
|
return unless @path
|
||||||
|
|
|
@ -17,15 +17,16 @@ require 'uri/generic'
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
#
|
#
|
||||||
# LDAP URI SCHEMA (described in RFC2255)
|
# LDAP URI SCHEMA (described in RFC2255).
|
||||||
|
#--
|
||||||
# ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
|
# ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
|
||||||
#
|
#++
|
||||||
class LDAP < Generic
|
class LDAP < Generic
|
||||||
|
|
||||||
# A Default port of 389 for URI::LDAP
|
# A Default port of 389 for URI::LDAP.
|
||||||
DEFAULT_PORT = 389
|
DEFAULT_PORT = 389
|
||||||
|
|
||||||
# An Array of the available components for URI::LDAP
|
# An Array of the available components for URI::LDAP.
|
||||||
COMPONENT = [
|
COMPONENT = [
|
||||||
:scheme,
|
:scheme,
|
||||||
:host, :port,
|
:host, :port,
|
||||||
|
@ -40,8 +41,8 @@ module URI
|
||||||
#
|
#
|
||||||
# * SCOPE_BASE - the Base DN
|
# * SCOPE_BASE - the Base DN
|
||||||
# * SCOPE_ONE - one level under the Base DN, not including the base DN and
|
# * SCOPE_ONE - one level under the Base DN, not including the base DN and
|
||||||
# not including any entries under this.
|
# not including any entries under this
|
||||||
# * SCOPE_SUB - subtress, all entries at all levels
|
# * SCOPE_SUB - subtrees, all entries at all levels
|
||||||
#
|
#
|
||||||
SCOPE = [
|
SCOPE = [
|
||||||
SCOPE_ONE = 'one',
|
SCOPE_ONE = 'one',
|
||||||
|
@ -52,7 +53,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Create a new URI::LDAP object from components, with syntax checking.
|
# Creates a new URI::LDAP object from components, with syntax checking.
|
||||||
#
|
#
|
||||||
# The components accepted are host, port, dn, attributes,
|
# The components accepted are host, port, dn, attributes,
|
||||||
# scope, filter, and extensions.
|
# scope, filter, and extensions.
|
||||||
|
@ -60,15 +61,15 @@ module URI
|
||||||
# The components should be provided either as an Array, or as a Hash
|
# The components should be provided either as an Array, or as a Hash
|
||||||
# with keys formed by preceding the component names with a colon.
|
# with keys formed by preceding the component names with a colon.
|
||||||
#
|
#
|
||||||
# If an Array is used, the components must be passed in the order
|
# If an Array is used, the components must be passed in the
|
||||||
# [host, port, dn, attributes, scope, filter, extensions].
|
# order <code>[host, port, dn, attributes, scope, filter, extensions]</code>.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# newuri = URI::LDAP.build({:host => 'ldap.example.com',
|
# uri = URI::LDAP.build({:host => 'ldap.example.com',
|
||||||
# :dn => '/dc=example'})
|
# :dn => '/dc=example'})
|
||||||
#
|
#
|
||||||
# newuri = URI::LDAP.build(["ldap.example.com", nil,
|
# uri = URI::LDAP.build(["ldap.example.com", nil,
|
||||||
# "/dc=example;dc=com", "query", nil, nil, nil])
|
# "/dc=example;dc=com", "query", nil, nil, nil])
|
||||||
#
|
#
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
|
@ -92,19 +93,18 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Create a new URI::LDAP object from generic URI components as per
|
# Creates a new URI::LDAP object from generic URI components as per
|
||||||
# RFC 2396. No LDAP-specific syntax checking is performed.
|
# RFC 2396. No LDAP-specific syntax checking is performed.
|
||||||
#
|
#
|
||||||
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
|
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
|
||||||
# +opaque+, +query+ and +fragment+, in that order.
|
# +opaque+, +query+, and +fragment+, in that order.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil, nil,
|
# uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil, nil,
|
||||||
# "/dc=example;dc=com", nil, "query", nil)
|
# "/dc=example;dc=com", nil, "query", nil)
|
||||||
#
|
#
|
||||||
#
|
# See also URI::Generic.new.
|
||||||
# See also URI::Generic.new
|
|
||||||
#
|
#
|
||||||
def initialize(*arg)
|
def initialize(*arg)
|
||||||
super(*arg)
|
super(*arg)
|
||||||
|
@ -117,14 +117,14 @@ module URI
|
||||||
parse_query
|
parse_query
|
||||||
end
|
end
|
||||||
|
|
||||||
# private method to cleanup +dn+ from using the +path+ component attribute
|
# Private method to cleanup +dn+ from using the +path+ component attribute.
|
||||||
def parse_dn
|
def parse_dn
|
||||||
@dn = @path[1..-1]
|
@dn = @path[1..-1]
|
||||||
end
|
end
|
||||||
private :parse_dn
|
private :parse_dn
|
||||||
|
|
||||||
# private method to cleanup +attributes+, +scope+, +filter+ and +extensions+,
|
# Private method to cleanup +attributes+, +scope+, +filter+, and +extensions+
|
||||||
# from using the +query+ component attribute
|
# from using the +query+ component attribute.
|
||||||
def parse_query
|
def parse_query
|
||||||
@attributes = nil
|
@attributes = nil
|
||||||
@scope = nil
|
@scope = nil
|
||||||
|
@ -142,7 +142,7 @@ module URI
|
||||||
end
|
end
|
||||||
private :parse_query
|
private :parse_query
|
||||||
|
|
||||||
# private method to assemble +query+ from +attributes+, +scope+, +filter+ and +extensions+.
|
# Private method to assemble +query+ from +attributes+, +scope+, +filter+, and +extensions+.
|
||||||
def build_path_query
|
def build_path_query
|
||||||
@path = '/' + @dn
|
@path = '/' + @dn
|
||||||
|
|
||||||
|
@ -155,12 +155,12 @@ module URI
|
||||||
end
|
end
|
||||||
private :build_path_query
|
private :build_path_query
|
||||||
|
|
||||||
# returns dn.
|
# Returns dn.
|
||||||
def dn
|
def dn
|
||||||
@dn
|
@dn
|
||||||
end
|
end
|
||||||
|
|
||||||
# private setter for dn +val+
|
# Private setter for dn +val+.
|
||||||
def set_dn(val)
|
def set_dn(val)
|
||||||
@dn = val
|
@dn = val
|
||||||
build_path_query
|
build_path_query
|
||||||
|
@ -168,18 +168,18 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_dn
|
protected :set_dn
|
||||||
|
|
||||||
# setter for dn +val+
|
# Setter for dn +val+.
|
||||||
def dn=(val)
|
def dn=(val)
|
||||||
set_dn(val)
|
set_dn(val)
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns attributes.
|
# Returns attributes.
|
||||||
def attributes
|
def attributes
|
||||||
@attributes
|
@attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
# private setter for attributes +val+
|
# Private setter for attributes +val+.
|
||||||
def set_attributes(val)
|
def set_attributes(val)
|
||||||
@attributes = val
|
@attributes = val
|
||||||
build_path_query
|
build_path_query
|
||||||
|
@ -187,18 +187,18 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_attributes
|
protected :set_attributes
|
||||||
|
|
||||||
# setter for attributes +val+
|
# Setter for attributes +val+.
|
||||||
def attributes=(val)
|
def attributes=(val)
|
||||||
set_attributes(val)
|
set_attributes(val)
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns scope.
|
# Returns scope.
|
||||||
def scope
|
def scope
|
||||||
@scope
|
@scope
|
||||||
end
|
end
|
||||||
|
|
||||||
# private setter for scope +val+
|
# Private setter for scope +val+.
|
||||||
def set_scope(val)
|
def set_scope(val)
|
||||||
@scope = val
|
@scope = val
|
||||||
build_path_query
|
build_path_query
|
||||||
|
@ -206,18 +206,18 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_scope
|
protected :set_scope
|
||||||
|
|
||||||
# setter for scope +val+
|
# Setter for scope +val+.
|
||||||
def scope=(val)
|
def scope=(val)
|
||||||
set_scope(val)
|
set_scope(val)
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns filter.
|
# Returns filter.
|
||||||
def filter
|
def filter
|
||||||
@filter
|
@filter
|
||||||
end
|
end
|
||||||
|
|
||||||
# private setter for filter +val+
|
# Private setter for filter +val+.
|
||||||
def set_filter(val)
|
def set_filter(val)
|
||||||
@filter = val
|
@filter = val
|
||||||
build_path_query
|
build_path_query
|
||||||
|
@ -225,18 +225,18 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_filter
|
protected :set_filter
|
||||||
|
|
||||||
# setter for filter +val+
|
# Setter for filter +val+.
|
||||||
def filter=(val)
|
def filter=(val)
|
||||||
set_filter(val)
|
set_filter(val)
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns extensions.
|
# Returns extensions.
|
||||||
def extensions
|
def extensions
|
||||||
@extensions
|
@extensions
|
||||||
end
|
end
|
||||||
|
|
||||||
# private setter for extensions +val+
|
# Private setter for extensions +val+.
|
||||||
def set_extensions(val)
|
def set_extensions(val)
|
||||||
@extensions = val
|
@extensions = val
|
||||||
build_path_query
|
build_path_query
|
||||||
|
@ -244,14 +244,14 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_extensions
|
protected :set_extensions
|
||||||
|
|
||||||
# setter for extensions +val+
|
# Setter for extensions +val+.
|
||||||
def extensions=(val)
|
def extensions=(val)
|
||||||
set_extensions(val)
|
set_extensions(val)
|
||||||
val
|
val
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if URI has a path
|
# Checks if URI has a path.
|
||||||
# For URI::LDAP this will return +false+
|
# For URI::LDAP this will return +false+.
|
||||||
def hierarchical?
|
def hierarchical?
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,15 +13,15 @@ require 'uri/generic'
|
||||||
module URI
|
module URI
|
||||||
|
|
||||||
#
|
#
|
||||||
# RFC6068, The mailto URL scheme
|
# RFC6068, the mailto URL scheme.
|
||||||
#
|
#
|
||||||
class MailTo < Generic
|
class MailTo < Generic
|
||||||
include REGEXP
|
include REGEXP
|
||||||
|
|
||||||
# A Default port of nil for URI::MailTo
|
# A Default port of nil for URI::MailTo.
|
||||||
DEFAULT_PORT = nil
|
DEFAULT_PORT = nil
|
||||||
|
|
||||||
# An Array of the available components for URI::MailTo
|
# An Array of the available components for URI::MailTo.
|
||||||
COMPONENT = [ :scheme, :to, :headers ].freeze
|
COMPONENT = [ :scheme, :to, :headers ].freeze
|
||||||
|
|
||||||
# :stopdoc:
|
# :stopdoc:
|
||||||
|
@ -62,26 +62,26 @@ module URI
|
||||||
# Creates a new URI::MailTo object from components, with syntax checking.
|
# Creates a new URI::MailTo object from components, with syntax checking.
|
||||||
#
|
#
|
||||||
# Components can be provided as an Array or Hash. If an Array is used,
|
# Components can be provided as an Array or Hash. If an Array is used,
|
||||||
# the components must be supplied as [to, headers].
|
# the components must be supplied as <code>[to, headers]</code>.
|
||||||
#
|
#
|
||||||
# If a Hash is used, the keys are the component names preceded by colons.
|
# If a Hash is used, the keys are the component names preceded by colons.
|
||||||
#
|
#
|
||||||
# The headers can be supplied as a pre-encoded string, such as
|
# The headers can be supplied as a pre-encoded string, such as
|
||||||
# "subject=subscribe&cc=address", or as an Array of Arrays like
|
# <code>"subject=subscribe&cc=address"</code>, or as an Array of Arrays
|
||||||
# [['subject', 'subscribe'], ['cc', 'address']]
|
# like <code>[['subject', 'subscribe'], ['cc', 'address']]</code>.
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
#
|
#
|
||||||
# require 'uri'
|
# require 'uri'
|
||||||
#
|
#
|
||||||
# m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
|
# m1 = URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
|
||||||
# puts m1.to_s -> mailto:joe@example.com?subject=Ruby
|
# m1.to_s # => "mailto:joe@example.com?subject=Ruby"
|
||||||
#
|
#
|
||||||
# m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
|
# m2 = URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
|
||||||
# puts m2.to_s -> mailto:john@example.com?Subject=Ruby&Cc=jack@example.com
|
# m2.to_s # => "mailto:john@example.com?Subject=Ruby&Cc=jack@example.com"
|
||||||
#
|
#
|
||||||
# m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
|
# m3 = URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
|
||||||
# puts m3.to_s -> mailto:listman@example.com?subject=subscribe
|
# m3.to_s # => "mailto:listman@example.com?subject=subscribe"
|
||||||
#
|
#
|
||||||
def self.build(args)
|
def self.build(args)
|
||||||
tmp = Util.make_components_hash(self, args)
|
tmp = Util.make_components_hash(self, args)
|
||||||
|
@ -160,13 +160,13 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The primary e-mail address of the URL, as a String
|
# The primary e-mail address of the URL, as a String.
|
||||||
attr_reader :to
|
attr_reader :to
|
||||||
|
|
||||||
# E-mail headers set by the URL, as an Array of Arrays
|
# E-mail headers set by the URL, as an Array of Arrays.
|
||||||
attr_reader :headers
|
attr_reader :headers
|
||||||
|
|
||||||
# check the to +v+ component
|
# Checks the to +v+ component.
|
||||||
def check_to(v)
|
def check_to(v)
|
||||||
return true unless v
|
return true unless v
|
||||||
return true if v.size == 0
|
return true if v.size == 0
|
||||||
|
@ -191,20 +191,20 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_to
|
private :check_to
|
||||||
|
|
||||||
# private setter for to +v+
|
# Private setter for to +v+.
|
||||||
def set_to(v)
|
def set_to(v)
|
||||||
@to = v
|
@to = v
|
||||||
end
|
end
|
||||||
protected :set_to
|
protected :set_to
|
||||||
|
|
||||||
# setter for to +v+
|
# Setter for to +v+.
|
||||||
def to=(v)
|
def to=(v)
|
||||||
check_to(v)
|
check_to(v)
|
||||||
set_to(v)
|
set_to(v)
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
# check the headers +v+ component against either
|
# Checks the headers +v+ component against either
|
||||||
# * HEADER_REGEXP
|
# * HEADER_REGEXP
|
||||||
def check_headers(v)
|
def check_headers(v)
|
||||||
return true unless v
|
return true unless v
|
||||||
|
@ -218,7 +218,7 @@ module URI
|
||||||
end
|
end
|
||||||
private :check_headers
|
private :check_headers
|
||||||
|
|
||||||
# private setter for headers +v+
|
# Private setter for headers +v+.
|
||||||
def set_headers(v)
|
def set_headers(v)
|
||||||
@headers = []
|
@headers = []
|
||||||
if v
|
if v
|
||||||
|
@ -229,14 +229,14 @@ module URI
|
||||||
end
|
end
|
||||||
protected :set_headers
|
protected :set_headers
|
||||||
|
|
||||||
# setter for headers +v+
|
# Setter for headers +v+.
|
||||||
def headers=(v)
|
def headers=(v)
|
||||||
check_headers(v)
|
check_headers(v)
|
||||||
set_headers(v)
|
set_headers(v)
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
|
|
||||||
# Constructs String from URI
|
# Constructs String from URI.
|
||||||
def to_s
|
def to_s
|
||||||
@scheme + ':' +
|
@scheme + ':' +
|
||||||
if @to
|
if @to
|
||||||
|
|
|
@ -58,7 +58,7 @@ module URI
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
end # REGEXP
|
end # REGEXP
|
||||||
|
|
||||||
# class that Parses String's into URI's
|
# Class that Parses String's into URI's.
|
||||||
#
|
#
|
||||||
# It contains a Hash set of patterns and Regexp's that match and validate.
|
# It contains a Hash set of patterns and Regexp's that match and validate.
|
||||||
#
|
#
|
||||||
|
@ -88,12 +88,12 @@ module URI
|
||||||
# == Examples
|
# == Examples
|
||||||
#
|
#
|
||||||
# p = URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
|
# p = URI::Parser.new(:ESCAPED => "(?:%[a-fA-F0-9]{2}|%u[a-fA-F0-9]{4})")
|
||||||
# u = p.parse("http://example.jp/%uABCD") #=> #<URI::HTTP:0xb78cf4f8 URL:http://example.jp/%uABCD>
|
# u = p.parse("http://example.jp/%uABCD") #=> #<URI::HTTP http://example.jp/%uABCD>
|
||||||
# URI.parse(u.to_s) #=> raises URI::InvalidURIError
|
# URI.parse(u.to_s) #=> raises URI::InvalidURIError
|
||||||
#
|
#
|
||||||
# s = "http://example.com/ABCD"
|
# s = "http://example.com/ABCD"
|
||||||
# u1 = p.parse(s) #=> #<URI::HTTP:0xb78c3220 URL:http://example.com/ABCD>
|
# u1 = p.parse(s) #=> #<URI::HTTP http://example.com/ABCD>
|
||||||
# u2 = URI.parse(s) #=> #<URI::HTTP:0xb78b6d54 URL:http://example.com/ABCD>
|
# u2 = URI.parse(s) #=> #<URI::HTTP http://example.com/ABCD>
|
||||||
# u1 == u2 #=> true
|
# u1 == u2 #=> true
|
||||||
# u1.eql?(u2) #=> false
|
# u1.eql?(u2) #=> false
|
||||||
#
|
#
|
||||||
|
@ -109,15 +109,15 @@ module URI
|
||||||
|
|
||||||
# The Hash of patterns.
|
# The Hash of patterns.
|
||||||
#
|
#
|
||||||
# see also URI::Parser.initialize_pattern
|
# See also URI::Parser.initialize_pattern.
|
||||||
attr_reader :pattern
|
attr_reader :pattern
|
||||||
|
|
||||||
# The Hash of Regexp
|
# The Hash of Regexp.
|
||||||
#
|
#
|
||||||
# see also URI::Parser.initialize_regexp
|
# See also URI::Parser.initialize_regexp.
|
||||||
attr_reader :regexp
|
attr_reader :regexp
|
||||||
|
|
||||||
# Returns a split URI against regexp[:ABS_URI]
|
# Returns a split URI against regexp[:ABS_URI].
|
||||||
def split(uri)
|
def split(uri)
|
||||||
case uri
|
case uri
|
||||||
when ''
|
when ''
|
||||||
|
@ -198,14 +198,14 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# parses +uri+ and constructs either matching URI scheme object
|
# Parses +uri+ and constructs either matching URI scheme object
|
||||||
# (FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or URI::Generic
|
# (file, FTP, HTTP, HTTPS, LDAP, LDAPS, or MailTo) or URI::Generic.
|
||||||
#
|
#
|
||||||
# == Usage
|
# == Usage
|
||||||
#
|
#
|
||||||
# p = URI::Parser.new
|
# p = URI::Parser.new
|
||||||
# p.parse("ldap://ldap.example.com/dc=example?user=john")
|
# p.parse("ldap://ldap.example.com/dc=example?user=john")
|
||||||
# #=> #<URI::LDAP:0x00000000b9e7e8 URL:ldap://ldap.example.com/dc=example?user=john>
|
# #=> #<URI::LDAP ldap://ldap.example.com/dc=example?user=john>
|
||||||
#
|
#
|
||||||
def parse(uri)
|
def parse(uri)
|
||||||
scheme, userinfo, host, port,
|
scheme, userinfo, host, port,
|
||||||
|
@ -231,7 +231,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Attempts to parse and merge a set of URIs
|
# Attempts to parse and merge a set of URIs.
|
||||||
#
|
#
|
||||||
def join(*uris)
|
def join(*uris)
|
||||||
uris[0] = convert_to_uri(uris[0])
|
uris[0] = convert_to_uri(uris[0])
|
||||||
|
@ -253,11 +253,11 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Attempts to parse and merge a set of URIs
|
# Attempts to parse and merge a set of URIs.
|
||||||
# If no +block+ given , then returns the result,
|
# If no +block+ given, then returns the result,
|
||||||
# else it calls +block+ for each element in result.
|
# else it calls +block+ for each element in result.
|
||||||
#
|
#
|
||||||
# see also URI::Parser.make_regexp
|
# See also URI::Parser.make_regexp.
|
||||||
#
|
#
|
||||||
def extract(str, schemes = nil)
|
def extract(str, schemes = nil)
|
||||||
if block_given?
|
if block_given?
|
||||||
|
@ -270,8 +270,8 @@ module URI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns Regexp that is default self.regexp[:ABS_URI_REF],
|
# Returns Regexp that is default self.regexp[:ABS_URI_REF],
|
||||||
# unless +schemes+ is provided. Then it is a Regexp.union with self.pattern[:X_ABS_URI]
|
# unless +schemes+ is provided. Then it is a Regexp.union with self.pattern[:X_ABS_URI].
|
||||||
def make_regexp(schemes = nil)
|
def make_regexp(schemes = nil)
|
||||||
unless schemes
|
unless schemes
|
||||||
@regexp[:ABS_URI_REF]
|
@regexp[:ABS_URI_REF]
|
||||||
|
@ -294,7 +294,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# constructs a safe String from +str+, removing unsafe characters,
|
# Constructs a safe String from +str+, removing unsafe characters,
|
||||||
# replacing them with codes.
|
# replacing them with codes.
|
||||||
#
|
#
|
||||||
def escape(str, unsafe = @regexp[:UNSAFE])
|
def escape(str, unsafe = @regexp[:UNSAFE])
|
||||||
|
@ -326,7 +326,7 @@ module URI
|
||||||
#
|
#
|
||||||
# == Description
|
# == Description
|
||||||
#
|
#
|
||||||
# Removes escapes from +str+
|
# Removes escapes from +str+.
|
||||||
#
|
#
|
||||||
def unescape(str, escaped = @regexp[:ESCAPED])
|
def unescape(str, escaped = @regexp[:ESCAPED])
|
||||||
enc = str.encoding
|
enc = str.encoding
|
||||||
|
@ -341,7 +341,7 @@ module URI
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Constructs the default Hash of patterns
|
# Constructs the default Hash of patterns.
|
||||||
def initialize_pattern(opts = {})
|
def initialize_pattern(opts = {})
|
||||||
ret = {}
|
ret = {}
|
||||||
ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
|
ret[:ESCAPED] = escaped = (opts.delete(:ESCAPED) || PATTERN::ESCAPED)
|
||||||
|
@ -499,7 +499,7 @@ module URI
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
# Constructs the default Hash of Regexp's
|
# Constructs the default Hash of Regexp's.
|
||||||
def initialize_regexp(pattern)
|
def initialize_regexp(pattern)
|
||||||
ret = {}
|
ret = {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue