[前][次][番号順一覧][スレッド一覧]

ruby-changes:20144

From: nahi <ko1@a...>
Date: Wed, 22 Jun 2011 02:44:59 +0900 (JST)
Subject: [ruby-changes:20144] nahi:r32192 (trunk): * lib/net/http.rb (Net::HTTP.post_form): Do not ignore query part of

nahi	2011-06-22 02:44:44 +0900 (Wed, 22 Jun 2011)

  New Revision: 32192

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32192

  Log:
    * lib/net/http.rb (Net::HTTP.post_form): Do not ignore query part of 
      the given URI to post. See #655.
    
    * test/net/http/test_http.rb, test/net/http/utils.rb: Test it.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/http.rb
    trunk/test/net/http/test_http.rb
    trunk/test/net/http/utils.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32191)
+++ ChangeLog	(revision 32192)
@@ -1,3 +1,10 @@
+Wed Jun 22 02:39:54 2011  Hiroshi Nakamura  <nahi@r...>
+
+	* lib/net/http.rb (Net::HTTP.post_form): Do not ignore query part of
+	  the given URI to post. See #655.
+
+	* test/net/http/test_http.rb, test/net/http/utils.rb: Test it.
+
 Wed Jun 22 01:28:13 2011  Hiroshi Nakamura  <nahi@r...>
 
 	* test/openssl/test_x509store.rb (test_set_errors): Redhat is
Index: lib/net/http.rb
===================================================================
--- lib/net/http.rb	(revision 32191)
+++ lib/net/http.rb	(revision 32192)
@@ -475,7 +475,7 @@
     #                  { "q" => "ruby", "max" => "50" }
     #
     def HTTP.post_form(url, params)
-      req = Post.new(url.path)
+      req = Post.new(url.request_uri)
       req.form_data = params
       req.basic_auth url.user, url.password if url.user
       new(url.hostname, url.port).start {|http|
Index: test/net/http/test_http.rb
===================================================================
--- test/net/http/test_http.rb	(revision 32191)
+++ test/net/http/test_http.rb	(revision 32192)
@@ -147,22 +147,30 @@
   end
 
   def test_s_post_form
+    url = "http://#{config('host')}:#{config('port')}/"
     res = Net::HTTP.post_form(
-              URI.parse("http://#{config('host')}:#{config('port')}/"),
+              URI.parse(url),
               "a" => "x")
     assert_equal ["a=x"], res.body.split(/[;&]/).sort
 
     res = Net::HTTP.post_form(
-              URI.parse("http://#{config('host')}:#{config('port')}/"),
+              URI.parse(url),
               "a" => "x",
               "b" => "y")
     assert_equal ["a=x", "b=y"], res.body.split(/[;&]/).sort
 
     res = Net::HTTP.post_form(
-              URI.parse("http://#{config('host')}:#{config('port')}/"),
+              URI.parse(url),
               "a" => ["x1", "x2"],
               "b" => "y")
+    assert_equal url, res['X-request-uri']
     assert_equal ["a=x1", "a=x2", "b=y"], res.body.split(/[;&]/).sort
+
+    res = Net::HTTP.post_form(
+              URI.parse(url + '?a=x'),
+              "b" => "y")
+    assert_equal url + '?a=x', res['X-request-uri']
+    assert_equal ["b=y"], res.body.split(/[;&]/).sort
   end
 
   def test_patch
Index: test/net/http/utils.rb
===================================================================
--- test/net/http/utils.rb	(revision 32191)
+++ test/net/http/utils.rb	(revision 32192)
@@ -91,6 +91,7 @@
     # echo server
     def do_POST(req, res)
       res['Content-Type'] = req['Content-Type']
+      res['X-request-uri'] = req.request_uri.to_s
       res.body = req.body
       res.chunked = @chunked
     end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]