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.

[Source]

        # File lib/phusion_passenger/rack/request_handler.rb, line 59
    59:         def initialize(owner_pipe, app, options = {})
    60:                 super(owner_pipe, options)
    61:                 @app = app
    62:         end

### Protected Instance methods

process_request(env, input, output)

Overrided method.

[Source]

         # File lib/phusion_passenger/rack/request_handler.rb, line 66
     66:         def process_request(env, input, output)
     67:                 rewindable_input = ::Rack::RewindableInput.new(input)
     68:                 begin
     69:                         env[RACK_VERSION]      = RACK_VERSION_VALUE
     70:                         env[RACK_INPUT]        = rewindable_input
     71:                         env[RACK_ERRORS]       = STDERR
     72:                         env[RACK_MULTITHREAD]  = false
     73:                         env[RACK_MULTIPROCESS] = true
     74:                         env[RACK_RUN_ONCE]     = false
     75:
     76:                         if env[HTTP_CONTENT_LENGTH] && env[CONTENT_LENGTH]
     77:                                 env.delete(HTTP_CONTENT_LENGTH)
     78:                         elsif env[HTTP_CONTENT_LENGTH] && !env[CONTENT_LENGTH]
     79:                                 env[CONTENT_LENGTH] = env[HTTP_CONTENT_LENGTH]
     80:                                 env.delete(HTTP_CONTENT_LENGTH)
     81:                         end
     82:                         if env[HTTP_CONTENT_TYPE] && env[CONTENT_TYPE]
     83:                                 env.delete(HTTP_CONTENT_TYPE)
     84:                         elsif env[HTTP_CONTENT_TYPE] && !env[CONTENT_TYPE]
     85:                                 env[CONTENT_TYPE] = env[HTTP_CONTENT_TYPE]
     86:                                 env.delete(HTTP_CONTENT_TYPE)
     87:                         end
     88:
     89:                         if env[HTTPS] == YES || env[HTTPS] == ON || env[HTTPS] == ONE
     90:                                 env[RACK_URL_SCHEME] = HTTPS_DOWNCASE
     91:                         else
     92:                                 env[RACK_URL_SCHEME] = HTTP
     93:                         end
     94:
     95:                         status, headers, body = @app.call(env)
     96:                         begin
     97:                                 output.write("Status: #{status.to_i}#{CRLF}")
     98:                                 output.write("X-Powered-By: #{PASSENGER_HEADER}#{CRLF}")
     99:                                 headers.each do |key, values|
    100:                                         if values.is_a?(String)
    101:                                                 values = values.split("\n")
    102:                                         end
    103:                                         values.each do |value|
    104:                                                 output.write("#{key}: #{value}#{CRLF}")
    105:                                         end
    106:                                 end
    107:                                 output.write(CRLF)
    108:                                 if body.is_a?(String)
    109:                                         output.write(body)
    110:                                 elsif body
    111:                                         body.each do |s|
    112:                                                 output.write(s)
    113:                                         end
    114:                                 end
    115:                         ensure
    116:                                 body.close if body.respond_to?(:close)
    117:                         end
    118:                 ensure
    119:                         rewindable_input.close
    120:                 end
    121:         end

[Validate]