=> true }.freeze ValidEncodings = { 'gzip' => true, 'deflate' => true }.freeze def initialize(app) @app = app end def call(env) if ValidMethods[env['REQUEST_METHOD']] && ValidEncodings[env['HTTP_CONTENT_ENCODING']] extracted = case env['HTTP_CONTENT_ENCODING'] when 'gzip' then Zlib::GzipReader.new(env['rack.input']).read when 'deflate' then Zlib::Inflate.inflate(env['rack.input'].read) end env.delete('HTTP_CONTENT_ENCODING') env['CONTENT_LENGTH'] = extracted.length env['rack.input'] = StringIO.new(extracted) end @app.call(env) end end