1 # -*- encoding: binary -*-
4 # allows storing pre-gzipped data on disk and serving it
5 # as-is for clients that accept that gzip encoding
6 module Metropolis::Gzip
8 status, headers, body = r = super
9 if 200 == status && /\bgzip\b/ !~ env['HTTP_ACCEPT_ENCODING']
10 body[0] = Zlib::GzipReader.new(StringIO.new(body[0])).read
11 headers['Content-Length'] = body[0].size.to_s
12 headers.delete('Content-Encoding')
13 headers.delete('Vary')
19 Wrapper.new(env) if 'gzip' != env['HTTP_CONTENT_ENCODING']
23 def self.extended(obj)
25 @headers['Content-Encoding'] = 'gzip'
26 @headers['Vary'] = 'Accept-Encoding'
30 class Wrapper < Metropolis::InputWrapper
33 zipped = StringIO.new("")
34 Zlib::GzipWriter.wrap(zipped) { |io| io.write(@input.read) }