A request handler for Rack applications.
Methods
Public Class methods
app is the Rack application object.
[ show source ]
# File lib/phusion_passenger/rack/request_handler.rb, line 60 60: def initialize(owner_pipe, app, options = {}) 61: super(owner_pipe, options) 62: @app = app 63: end
Protected Instance methods
Overrided method.
[ show source ]
# File lib/phusion_passenger/rack/request_handler.rb, line 67 67: def process_request(env, input, output) 68: rewindable_input = ::Rack::RewindableInput.new(input) 69: begin 70: env[RACK_VERSION] = RACK_VERSION_VALUE 71: env[RACK_INPUT] = rewindable_input 72: env[RACK_ERRORS] = STDERR 73: env[RACK_MULTITHREAD] = false 74: env[RACK_MULTIPROCESS] = true 75: env[RACK_RUN_ONCE] = false 76: env[QUERY_STRING] ||= "" 77: env[PATH_INFO] ||= env[REQUEST_URI].split(QUESTION_MARK, 2).first 78: env[PATH_INFO].sub!(/^#{Regexp.escape(env[SCRIPT_NAME])}/, "") 79: if env[HTTP_CONTENT_LENGTH] && env[CONTENT_LENGTH] 80: env.delete(HTTP_CONTENT_LENGTH) 81: elsif env[HTTP_CONTENT_LENGTH] && !env[CONTENT_LENGTH] 82: env[CONTENT_LENGTH] = env[HTTP_CONTENT_LENGTH] 83: env.delete(HTTP_CONTENT_LENGTH) 84: end 85: if env[HTTPS] == YES || env[HTTPS] == ON || env[HTTPS] == ONE 86: env[RACK_URL_SCHEME] = HTTPS_DOWNCASE 87: else 88: env[RACK_URL_SCHEME] = HTTP 89: end 90: 91: status, headers, body = @app.call(env) 92: begin 93: output.write("Status: #{status.to_i}#{CRLF}") 94: output.write("X-Powered-By: #{PASSENGER_HEADER}#{CRLF}") 95: headers.each do |key, values| 96: if values.is_a?(String) 97: values = values.split("\n") 98: end 99: values.each do |value| 100: output.write("#{key}: #{value}#{CRLF}") 101: end 102: end 103: output.write(CRLF) 104: if body.is_a?(String) 105: output.write(body) 106: elsif body 107: body.each do |s| 108: output.write(s) 109: end 110: end 111: ensure 112: body.close if body.respond_to?(:close) 113: end 114: ensure 115: rewindable_input.close 116: end 117: end