Class: Stickler::Middleware::Compression
- Inherits:
-
Object
- Object
- Stickler::Middleware::Compression
- Defined in:
- lib/stickler/middleware/compression.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Compression
constructor
A new instance of Compression.
Constructor Details
#initialize(app) ⇒ Compression
Returns a new instance of Compression.
5 6 7 |
# File 'lib/stickler/middleware/compression.rb', line 5 def initialize( app ) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stickler/middleware/compression.rb', line 9 def call( env ) status, headers, body = @app.call( env ) return [ status, headers, body ] unless status == 200 headers = ::Rack::Utils::HeaderHash.new( headers ) stream = body if compress_method = env['stickler.compression'] then headers.delete('Content-Length') case compress_method when :gzip headers['Content-Type'] = 'application/x-gzip' stream = Gem.gzip( body.first ) when :deflate headers['Content-Type'] = 'application/x-deflate' stream = Gem.deflate( body.first ) end end return [ status, headers, stream ] end |