Max Williams
Max Williams

Reputation: 32945

Rails: how to unzip a compressed xml request body?

I have a rails 3 site which gets xml requests (incluing file submissions) from an iphone app. The iphone app compresses the body of its xml requests, which come through to my controller like this (this is a simple one that just updates a couple of details rather than sends any files):

params = {"\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x035\xCAA\x0E\x83 \x10@\xD1\xD3\xE8\xD20\x02R\x17\xDD4\xBD\x87\x01\x9CZ\"H\x03CHo\xDF\xB2`\xFB\xDFO\xF8\x89\x89\x06\xF9\xA81\x9D/\x1F\xEB\x96IS\xC9\x83|\xDE\xF9\x98\xBA\xE2E\xE9\xBB\xD9X.j\xC2F"=>{"\xE8\xFD\xEF\xE4\x02\xB6\x00\x1C\x18\x13\x1C\xA4\xEC\x82A"=>nil}, "\xDF\x88\xA2\xCEt\xBA}\xAA\xCE{\xA7C\x1E\x04"=>nil, "\x1AN6\x86~gw\xB4\xD7\x00\x82\xE0r\xC1\x9D\x8B\xDB\xAC\xD6uF.\xCCb%\x03\x83\xA0\xD4\x0F~\xA0o\x1F\xAE\x00\x00"=>nil, "action"=>"update", "controller"=>"reports", "id"=>"65", "format"=>"xml"}

It should look something like this:

params = {"report"=>{"workflow_status"=>"-1", "entry_count"=>"0"}, "auth"=>{"time"=>"1310044269", "email"=>"[email protected]", "sig"=>"686062dbc27ef49baa69be77a0ba6362"}, "action"=>"update", "controller"=>"reports", "id"=>"65", "format"=>"xml"}

Note that the first example is NOT a compressed version of the second, ie some of the values will be different, but the overall structure should be the same (once it's unzipped).

Can anyone tell me how i unzip it? The zipped params come from the request body, which will also include filedata in some cases.

grateful for any advice - max

Upvotes: 2

Views: 1838

Answers (1)

Seamus Abshere
Seamus Abshere

Reputation: 8526

You may be able to use Richard Schneeman's answer:

Mime::Type.register "gzip/json", :gzipjson
config.middleware.delete "ActionDispatch::ParamsParser"
config.middleware.use ActionDispatch::ParamsParser , { Mime::GZIPJSON => Proc.new { |raw_request | data = ActiveSupport::JSON.decode(ActiveSupport::Gzip.decompress(raw_request)); data = {:_json => data} unless data.is_a?(Hash); data.with_indifferent_access }}

That should go in config/environment.rb

Upvotes: 5

Related Questions