GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Hongli Lai (Phusion) (author)
Fri May 09 10:53:45 -0700 2008
commit  ad9d1365ddc9271244c127cd9c1dbcc462514b29
tree    b8d327b3f1153271017cc05162db0f7ce8503c53
parent  5d0fb07a71c1f77fb80e2ac9644936f1cefef700
passenger / lib / passenger / rails / request_handler.rb
100644 64 lines (54 sloc) 1.962 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Phusion Passenger - http://www.modrails.com/
# Copyright (C) 2008 Phusion
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
require 'passenger/passenger'
module Passenger
module Rails
 
# A request handler for Ruby on Rails applications.
class RequestHandler < AbstractRequestHandler
  # String constants which exist to relieve Ruby's garbage collector.
  
  
  NINJA_PATCHING_LOCK = Mutex.new
  @@ninja_patched_action_controller = false
  
  def initialize(owner_pipe)
    super(owner_pipe)
    NINJA_PATCHING_LOCK.synchronize do
      ninja_patch_action_controller
    end
  end
 
protected
  # Overrided method.
  def process_request(headers, input, output)
    cgi = CGIFixed.new(headers, input, output)
    ::Dispatcher.dispatch(cgi,
      ::ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS,
      cgi.stdoutput)
  end
  
private
  def ninja_patch_action_controller
    if !@@ninja_patched_action_controller && defined?(::ActionController::Base) \
    && ::ActionController::Base.private_method_defined?(:perform_action)
      @@ninja_patched_action_controller = true
      ::ActionController::Base.class_eval do
        alias passenger_orig_perform_action perform_action
        
        def perform_action(*whatever)
          headers[X_POWERED_BY] = PASSENGER_HEADER
          passenger_orig_perform_action(*whatever)
        end
      end
    end
  end
end
 
end # module Rails
end # module Passenger