Created
January 30, 2012 17:09
-
-
Save schneems/1705468 to your computer and use it in GitHub Desktop.
Receive GZIP params in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_gzip_params | |
# When the server receives a request with content-type "gzip/json" this will be called which will unzip it, | |
# and then parse it as json | |
# The use case is so clients such as Android or Iphone can zip their long request such as Inviters#addressbook emails | |
# Then the server can unpack the request and parse the parameters as normal. | |
if request.content_type == "gzip/json" | |
data = ActiveSupport::JSON.decode(ActiveSupport::Gzip.decompress(request.raw_post)) | |
data = {:_json => data} unless data.is_a?(Hash) | |
params ||= {} | |
self.params.merge!(data.to_options) #params.merge(data.with_indifferent_access).inject({}){|temp,(k,v)| temp[k.to_sym] = v; temp} # replace string keys with symbols | |
end | |
end |
Rack::Deflater
is used to compress http responses, not receive compressed http requests.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isn't easier to just use
use Rack::Deflater
?