diff --git a/ChangeLog b/ChangeLog index 534b38cd3a..074b33ad29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Mar 7 07:43:29 2012 Aaron Patterson + + * 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 * test/xmlrpc/test_client.rb: adding a test for performing an XMLRPC diff --git a/lib/xmlrpc/client.rb b/lib/xmlrpc/client.rb index 8d899bc600..a75067ab8b 100644 --- a/lib/xmlrpc/client.rb +++ b/lib/xmlrpc/client.rb @@ -556,7 +556,9 @@ module XMLRPC 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}" diff --git a/test/xmlrpc/test_client.rb b/test/xmlrpc/test_client.rb index a509aec0c4..d0e47b17d6 100644 --- a/test/xmlrpc/test_client.rb +++ b/test/xmlrpc/test_client.rb @@ -188,7 +188,7 @@ module XMLRPC rest.each { |x| refute x } end - def test_bad_content_type + def test_request fh = read 'blog.xml' responses = { @@ -210,6 +210,29 @@ module XMLRPC 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))