Ticket #8568: added_deflate_support.diff
| File added_deflate_support.diff, 2.5 kB (added by foeken, 2 years ago) |
|---|
-
test/connection_test.rb
old new 1 1 require "#{File.dirname(__FILE__)}/abstract_unit" 2 2 require 'base64' 3 require 'zlib' 3 4 4 5 class ConnectionTest < Test::Unit::TestCase 5 6 ResponseCodeStub = Struct.new(:code) … … 22 23 mock.get "/people_single_elements.xml", {}, @people_single 23 24 mock.get "/people_empty_elements.xml", {}, @people_empty 24 25 mock.get "/people/1.xml", {}, @matz 26 mock.get "/people/3.xml", {}, Zlib::Deflate.deflate(@matz), 200, { 'content-encoding' => 'deflate' } 25 27 mock.put "/people/1.xml", {}, nil, 204 26 28 mock.put "/people/2.xml", {}, @header, 204 27 29 mock.delete "/people/1.xml", {}, nil, 200 … … 96 98 matz = @conn.get("/people/1.xml") 97 99 assert_equal "Matz", matz["name"] 98 100 end 99 101 100 102 def test_get_with_header 101 103 david = @conn.get("/people/2.xml", @header) 102 104 assert_equal "David", david["name"] 103 105 end 106 107 def test_get_deflated_header 108 matz = @conn.get("/people/3.xml") 109 assert_equal "Matz", matz["name"] 110 end 104 111 105 112 def test_get_collection 106 113 people = @conn.get("/people.xml") -
lib/active_resource/connection.rb
old new 81 81 end 82 82 83 83 def xml_from_response(response) 84 if response = from_xml_data(Hash.from_xml(response.body)) 84 85 # Check the content-encoding header and act accordingly 86 case response.header["content-encoding"] 87 when "deflate" then response_body = Zlib::Inflate.inflate(response.body) 88 else response_body = response.body 89 end 90 91 if response = from_xml_data(Hash.from_xml(response_body)) 85 92 response.first 86 93 else 87 94 nil 88 95 end 96 89 97 end 90 98 91 99 -
lib/active_resource/http_mock.rb
old new 98 98 @body, @message, @headers = body, message.to_s, headers 99 99 @code = @message[0,3].to_i 100 100 end 101 102 # Added this, since in real life the headers are called header :/ 103 def header 104 headers 105 end 106 107 def header=(header) 108 headers 109 end 101 110 102 111 def success? 103 112 (200..299).include?(code)