From 54eb51f7ad3da53fd40ce54c603724c76940ec80 Mon Sep 17 00:00:00 2001 From: hsbt Date: Fri, 30 Sep 2016 10:06:24 +0000 Subject: * 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 --- lib/uri/http.rb | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'lib/uri') diff --git a/lib/uri/http.rb b/lib/uri/http.rb index 81ae846fd9..d4373e73e5 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 -- cgit v1.2.3