rename application.rb to rails 2.3 compatible way, add symlink for
[opensuse:software-o-o.git] / app / controllers / application_controller.rb
1 # Filters added to this controller apply to all controllers in the application.
2 # Likewise, all the methods added will be available for all controllers.
3
4 require 'stringio'
5 require 'zlib'
6
7 class ApplicationController < ActionController::Base
8   # Pick a unique cookie name to distinguish our session data from others'
9   # session :session_key => '_software_session_id'
10   session :disabled => true
11   layout "application_no_js"
12
13   after_filter :set_vary_header
14   after_filter :compress
15
16   def set_vary_header
17     self.response.headers['Vary'] = 'Accept-Encoding'
18   end
19
20   def compress
21     enc = self.request.env['HTTP_ACCEPT_ENCODING']
22     if enc and (md = enc.match(/gzip;?(q=([^,]*))?/))
23       if md[1].nil? or md[2].to_f > 0.0
24         if self.response.headers["Content-Transfer-Encoding"] != 'binary'
25           logger.debug "compressing output"
26           begin 
27             ostream = StringIO.new
28             gz = Zlib::GzipWriter.new(ostream)
29             gz.write(self.response.body)
30             self.response.body = ostream.string
31             self.response.headers['Content-Encoding'] = 'gzip'
32           ensure
33             gz.close
34           end
35         end
36       end
37     end
38   end
39
40   def rescue_action_in_public(exception)
41     @message = exception.message
42     if request.xhr?
43       render :template => "error", :layout => :false, :status => 404
44     else
45       render :template => 'error', :layout => "application", :status => 404
46     end
47   end
48 end