Created
October 20, 2010 00:05
Revisions
-
There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ class CompressedRequests def initialize(app) @app = app end def call(env) if env['REQUEST_METHOD'] =~ /(POST|PUT)/ if env.keys.include? 'HTTP_CONTENT_ENCODING' input = env['rack.input'].read new_input = decode(input, env['HTTP_CONTENT_ENCODING']) env['rack.input'] = StringIO.new(new_input) env['CONTENT_LENGTH'] = new_input.length env.delete('HTTP_CONTENT_ENCODING') end end status, headers, response = @app.call(env) return [status, headers, response] end def decode(input, content_encoding) if content_encoding == 'gzip' z = Zlib::GzipReader.new(StringIO.new(input)).read elsif content_encoding == 'deflate' Zlib::Inflate.new.inflate new input else input end end end