ruby-changes:22886
From: tenderlove <ko1@a...>
Date: Wed, 7 Mar 2012 07:45:53 +0900 (JST)
Subject: [ruby-changes:22886] tenderlove:r34935 (trunk): * lib/xmlrpc/client.rb: assume servers that do not send a Content-Type
tenderlove 2012-03-07 07:45:43 +0900 (Wed, 07 Mar 2012) New Revision: 34935 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34935 Log: * lib/xmlrpc/client.rb: assume servers that do not send a Content-Type header are sending 'text/xml'. Thanks Nathan Leavitt! [ruby-core:41204] [Bug #5660] * test/xmlrpc/test_client.rb: supporting test Modified files: trunk/ChangeLog trunk/lib/xmlrpc/client.rb trunk/test/xmlrpc/test_client.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34934) +++ ChangeLog (revision 34935) @@ -1,3 +1,11 @@ +Wed Mar 7 07:43:29 2012 Aaron Patterson <aaron@t...> + + * lib/xmlrpc/client.rb: assume servers that do not send a Content-Type + header are sending 'text/xml'. Thanks Nathan Leavitt! + [ruby-core:41204] [Bug #5660] + + * test/xmlrpc/test_client.rb: supporting test + Wed Mar 7 07:39:28 2012 Aaron Patterson <aaron@t...> * test/xmlrpc/test_client.rb: adding a test for performing an XMLRPC Index: lib/xmlrpc/client.rb =================================================================== --- lib/xmlrpc/client.rb (revision 34934) +++ lib/xmlrpc/client.rb (revision 34935) @@ -556,7 +556,9 @@ raise "HTTP-Error: #{resp.code} #{resp.message}" end - ct = parse_content_type(resp["Content-Type"]).first + # assume text/xml on instances where Content-Type header is not set + ct_expected = resp["Content-Type"] || 'text/xml' + ct = parse_content_type(ct_expected).first if ct != "text/xml" if ct == "text/html" raise "Wrong content-type (received '#{ct}' but expected 'text/xml'): \n#{data}" Index: test/xmlrpc/test_client.rb =================================================================== --- test/xmlrpc/test_client.rb (revision 34934) +++ test/xmlrpc/test_client.rb (revision 34935) @@ -188,7 +188,7 @@ rest.each { |x| refute x } end - def test_bad_content_type + def test_request fh = read 'blog.xml' responses = { @@ -210,6 +210,29 @@ assert_equal expected, resp end + # make a request without content-type header + def test_bad_content_type + fh = read 'blog.xml' + + responses = { + '/foo' => [ Fake::Response.new(fh) ] + } + + client = fake_client(responses).new2 'http://example.org/foo' + + resp = client.call('wp.getUsersBlogs', 'tlo', 'omg') + + expected = [{ + "isAdmin" => true, + "url" => "http://tenderlovemaking.com/", + "blogid" => "1", + "blogName" => "Tender Lovemaking", + "xmlrpc" => "http://tenderlovemaking.com/xmlrpc.php" + }] + + assert_equal expected, resp + end + private def read filename File.read File.expand_path(File.join(__FILE__, '..', 'data', filename)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/