summaryrefslogtreecommitdiff
path: root/lib/uri/http.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-30 10:06:24 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-09-30 10:06:24 +0000
commit107ba65fba13bdf791e5dae0305c5768e6f7d122 (patch)
treedd3288a693b9f8752d46ffc91d9342133edbac9f /lib/uri/http.rb
parent377f69e4fef4c9fd11934a19c672606875036a19 (diff)
* lib/uri/http.rb: Documentation and code style imrovements.
* test/uri/test_http.rb: Added test for coverage. [fix GH-1427][ruby-core:77255][Misc #12756] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/uri/http.rb')
-rw-r--r--lib/uri/http.rb35
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/uri/http.rb b/lib/uri/http.rb
index 81ae846fd96..d4373e73e51 100644
--- a/lib/uri/http.rb
+++ b/lib/uri/http.rb
@@ -25,12 +25,12 @@ module URI
DEFAULT_PORT = 80
# An Array of the available components for URI::HTTP
- COMPONENT = [
- :scheme,
- :userinfo, :host, :port,
- :path,
- :query,
- :fragment
+ COMPONENT = %i[
+ scheme
+ userinfo host port
+ path
+ query
+ fragment
].freeze
#
@@ -49,8 +49,7 @@ module URI
#
# Example:
#
- # newuri = URI::HTTP.build({:host => 'www.example.com',
- # :path => '/foo/bar'})
+ # newuri = URI::HTTP.build(host: 'www.example.com', path: '/foo/bar')
#
# newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
# "query", 'fragment'])
@@ -59,8 +58,8 @@ module URI
# invalid HTTP URIs as per RFC 1738.
#
def self.build(args)
- tmp = Util::make_components_hash(self, args)
- return super(tmp)
+ tmp = Util.make_components_hash(self, args)
+ super(tmp)
end
=begin
@@ -95,15 +94,19 @@ module URI
# If the URI contains a query, the full path is URI#path + '?' + URI#query.
# Otherwise, the path is simply URI#path.
#
+ # Example:
+ #
+ # newuri = URI::HTTP.build(path: '/foo/bar', query: 'test=true')
+ # newuri.request_uri # => "/foo/bar?test=true"
+ #
def request_uri
- return nil unless @path
- if @path.start_with?(?/.freeze)
- @query ? "#@path?#@query" : @path.dup
- else
- @query ? "/#@path?#@query" : "/#@path"
- end
+ return unless @path
+
+ url = @query ? "#@path?#@query" : @path.dup
+ url.start_with?(?/.freeze) ? url : ?/ + url
end
end
@@schemes['HTTP'] = HTTP
+
end