# File lib/mongrel_output_compression/init.rb, line 20
20:    def process(request, response)
21:       return if COMPRESSION_DISABLED || request.params["HTTP_ACCEPT_ENCODING"].nil?
22:       begin
23:          request.params["HTTP_ACCEPT_ENCODING"].split(/\s*,\s*/).each do |encoding|
24:            case encoding
25:               when /\Agzip\b/
26:                  strio = StringIO.new
27:                  def strio.close
28:                     rewind 
29:                  end
30:                  gz = Zlib::GzipWriter.new(strio)
31:                  gz.write(response.body.string)
32:                  gz.close
33:                  response.body = strio
34:                  response.body.rewind
35:               when /\Adeflate\b/
36:                  response.body = StringIO.new(Zlib::Deflate.deflate(response.body.string))
37:                  response.body.rewind
38:               when /\Aidentity\b/
39:                  # do nothing for identity
40:               else
41:                  next # the encoding is not supported, try the next one
42:            end
43:            @content_type = encoding
44:            break    # the encoding is supported, stop
45:          end
46:          response.header['Content-Encoding'] = @content_type
47:          # if response.header['Vary'] != '*'
48:          #    head['Vary'] = response.header['Vary'].to_s.split(',').push('Accept-Encoding').uniq.join(',')
49:          # end
50:          STDERR.puts "Response body was encoded with #{@content_type}\n"
51:       rescue Exception => e
52:          STDERR.puts "Error with HTTP Compression: #{e.to_s}\n"
53:          response.start(500, true) do |head, out|
54:             out.write "error proceessing #{request.params['REQUEST_PATH']}\n"
55:          end
56:       end
57:    end