Class
PhusionPassenger::Rack::RequestHandler

In: | lib/phusion_passenger/rack/request_handler.rb
Parent: | AbstractRequestHandler

A request handler for Rack applications.

Methods

- new
- process_request

Public Class methods
new(owner_pipe, app, options = {})

`app` is the Rack application object.

[ show source ]

        # File lib/phusion_passenger/rack/request_handler.rb, line 43
    43:         def initialize(owner_pipe, app, options = {})
    44:                 super(owner_pipe, options)
    45:                 @app = app
    46:         end

Protected Instance methods
process_request(env, input, output)

Overrided method.

[ show source ]

        # File lib/phusion_passenger/rack/request_handler.rb, line 50
    50:         def process_request(env, input, output)
    51:                 env[RACK_VERSION]      = RACK_VERSION_VALUE
    52:                 env[RACK_INPUT]        = input
    53:                 env[RACK_ERRORS]       = STDERR
    54:                 env[RACK_MULTITHREAD]  = false
    55:                 env[RACK_MULTIPROCESS] = true
    56:                 env[RACK_RUN_ONCE]     = false
    57:                 env[SCRIPT_NAME]     ||= ''
    58:                 env[PATH_INFO].sub!(/^#{Regexp.escape(env[SCRIPT_NAME])}/, "")
    59:                 if env[HTTPS] == YES || env[HTTPS] == ON || env[HTTPS] == ONE
    60:                         env[RACK_URL_SCHEME] = HTTPS_DOWNCASE
    61:                 else
    62:                         env[RACK_URL_SCHEME] = HTTP
    63:                 end
    64:
    65:                 status, headers, body = @app.call(env)
    66:                 begin
    67:                         output.write("Status: #{status}#{CRLF}")
    68:                         headers[X_POWERED_BY] = PASSENGER_HEADER
    69:                         headers.each_pair do |key, values|
    70:                                 if values.is_a?(String)
    71:                                         values = values.split("\n")
    72:                                 end
    73:                                 values.each do |value|
    74:                                         output.write("#{key}: #{value}#{CRLF}")
    75:                                 end
    76:                         end
    77:                         output.write(CRLF)
    78:                         if body.is_a?(String)
    79:                                 output.write(body)
    80:                         elsif body
    81:                                 body.each do |s|
    82:                                         output.write(s)
    83:                                 end
    84:                         end
    85:                 ensure
    86:                         body.close if body.respond_to?(:close)
    87:                 end
    88:         end