-
-
Save zerobearing2/e935a557a5584aaaef19 to your computer and use it in GitHub Desktop.
Revisions
-
zerobearing2 revised this gist
Aug 27, 2014 . 2 changed files with 37 additions and 33 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -1,33 +0,0 @@ This file contains hidden or 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,37 @@ module Rack # # Deflate/ungzip request body # class DeflateRequest def initialize(app) @app = app end def method_handled?(env) !!(env['REQUEST_METHOD'] =~ /(POST|PUT)/) end def encoding_handled?(env) ['gzip', 'deflate'].include? env['HTTP_CONTENT_ENCODING'] end def call(env) if method_handled?(env) && encoding_handled?(env) extracted = decode(env['rack.input'], env['HTTP_CONTENT_ENCODING']) env['X_REQUEST_CONTENT_ENCODING'] = env.delete('HTTP_CONTENT_ENCODING') env['CONTENT_LENGTH'] = extracted.bytesize env['rack.input'] = StringIO.new(extracted) end @app.call(env) end def decode(input, content_encoding) case content_encoding when 'gzip' then Zlib::GzipReader.new(input).read when 'deflate' then Zlib::Inflate.inflate(input.read) end end end end -
relistan revised this gist
Mar 30, 2012 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 @@ -8,7 +8,6 @@ def method_handled?(env) end def encoding_handled?(env) ['gzip', 'deflate'].include? env['HTTP_CONTENT_ENCODING'] end -
relistan revised this gist
Mar 30, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 @@ -8,7 +8,7 @@ def method_handled?(env) end def encoding_handled?(env) return false unless env['HTTP_CONTENT_ENCODING'] ['gzip', 'deflate'].include? env['HTTP_CONTENT_ENCODING'] end -
relistan revised this gist
Mar 21, 2012 . 1 changed file with 7 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -3,19 +3,18 @@ def initialize(app) @app = app end def method_handled?(env) !!(env['REQUEST_METHOD'] =~ /(POST|PUT)/) end def encoding_handled?(env) return false unless env.keys.include?('HTTP_CONTENT_ENCODING') ['gzip', 'deflate'].include? env['HTTP_CONTENT_ENCODING'] end def call(env) if method_handled?(env) && encoding_handled?(env) extracted = decode(env['rack.input'], env['HTTP_CONTENT_ENCODING']) env.delete('HTTP_CONTENT_ENCODING') env['CONTENT_LENGTH'] = extracted.length @@ -27,12 +26,9 @@ def call(env) end def decode(input, content_encoding) case content_encoding when 'gzip' then Zlib::GzipReader.new(input).read when 'deflate' then Zlib::Inflate.inflate(input.read) end end end -
relistan revised this gist
Mar 21, 2012 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -14,13 +14,12 @@ def encoding_handled?(env) def call(env) if action_handled?(env) && encoding_handled?(env) input = env['rack.input'] extracted = decode(input, env['HTTP_CONTENT_ENCODING']) env.delete('HTTP_CONTENT_ENCODING') env['CONTENT_LENGTH'] = extracted.length env['rack.input'] = StringIO.new(extracted) end status, headers, response = @app.call(env) @@ -29,11 +28,11 @@ def call(env) def decode(input, content_encoding) if content_encoding == 'gzip' Zlib::GzipReader.new(input).read elsif content_encoding == 'deflate' Zlib::Inflate.inflate(input.read) else input.read end end end -
relistan revised this gist
Mar 21, 2012 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -11,10 +11,6 @@ def encoding_handled?(env) return false unless env.keys.include?('HTTP_CONTENT_ENCODING') ['gzip', 'deflate'].include? env['HTTP_CONTENT_HANDLING'] end def call(env) if action_handled?(env) && encoding_handled?(env) -
relistan revised this gist
Mar 21, 2012 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -11,18 +11,20 @@ def encoding_handled?(env) return false unless env.keys.include?('HTTP_CONTENT_ENCODING') ['gzip', 'deflate'].include? env['HTTP_CONTENT_HANDLING'] end def inflate_stream(stream) end def call(env) if action_handled?(env) && encoding_handled?(env) input = env['rack.input'].read new_input = decode(input, env['HTTP_CONTENT_ENCODING']) env.delete('HTTP_CONTENT_ENCODING') env['rack.input'] = StringIO.new(new_input) env['CONTENT_LENGTH'] = new_input.length end status, headers, response = @app.call(env) -
relistan revised this gist
Mar 19, 2012 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -4,8 +4,7 @@ def initialize(app) end def action_handled?(env) !!(env['REQUEST_METHOD'] =~ /(POST|PUT)/) end def encoding_handled?(env) -
relistan revised this gist
Mar 19, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 @@ -8,7 +8,7 @@ def action_handled?(env) true end def encoding_handled?(env) return false unless env.keys.include?('HTTP_CONTENT_ENCODING') ['gzip', 'deflate'].include? env['HTTP_CONTENT_HANDLING'] end -
relistan revised this gist
Mar 19, 2012 . 1 changed file with 19 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 @@ -2,19 +2,28 @@ class CompressedRequests def initialize(app) @app = app end def action_handled?(env) return false unless env['REQUEST_METHOD'] =~ /(POST|PUT)/ true end encoding_handled?(env) return false unless env.keys.include?('HTTP_CONTENT_ENCODING') ['gzip', 'deflate'].include? env['HTTP_CONTENT_HANDLING'] end def call(env) if action_handled?(env) && encoding_handled?(env) input = env['rack.input'].read new_input = decode(input, env['HTTP_CONTENT_ENCODING']) # We'll only delete this if we handled it env.delete('HTTP_CONTENT_ENCODING') if input != new_input env['rack.input'] = StringIO.new(new_input) env['CONTENT_LENGTH'] = new_input.length end status, headers, response = @app.call(env) @@ -23,7 +32,7 @@ def call(env) def decode(input, content_encoding) if content_encoding == 'gzip' Zlib::GzipReader.new(StringIO.new(input)).read elsif content_encoding == 'deflate' Zlib::Inflate.new.inflate new input else -
There are no files selected for viewing
This file contains hidden or 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