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
7 include Metropolis::Constants
11 status, headers, body = r = super
12 if 200 == status && /\bgzip\b/ !~ env[HTTP_ACCEPT_ENCODING]
13 body[0] = Zlib::GzipReader.new(StringIO.new(body[0])).read
14 headers[Content_Length] = body[0].size.to_s
15 headers.delete(Content_Encoding)
22 Wrapper.new(env) if Compression != env[HTTP_CONTENT_ENCODING]
26 def self.extended(obj)
28 @headers[Content_Encoding] = Compression
29 @headers[Vary] = Accept_Encoding
33 class Wrapper < Metropolis::InputWrapper
36 zipped = StringIO.new("")
37 Zlib::GzipWriter.wrap(zipped) { |io| io.write(@input.read) }