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 56
    56:         def initialize(owner_pipe, app, options = {})
    57:                 super(owner_pipe, options)
    58:                 @app = app
    59:         end

### Protected Instance methods

process_request(env, input, output)

Overrided method.

[Source]

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

[Validate]