::Mongrel::HttpHandler
# File lib/rack/handler/mongrel.rb, line 51 51: def initialize(app) 52: @app = app 53: end
# File lib/rack/handler/mongrel.rb, line 9 9: def self.run(app, options={}) 10: server = ::Mongrel::HttpServer.new( 11: options[:Host] || '0.0.0.0', 12: options[:Port] || 8080, 13: options[:num_processors] || 950, 14: options[:throttle] || 0, 15: options[:timeout] || 60) 16: # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods. 17: # Use is similar to #run, replacing the app argument with a hash of 18: # { path=>app, ... } or an instance of Rack::URLMap. 19: if options[:map] 20: if app.is_a? Hash 21: app.each do |path, appl| 22: path = '/'+path unless path[0] == // 23: server.register(path, Rack::Handler::Mongrel.new(appl)) 24: end 25: elsif app.is_a? URLMap 26: app.instance_variable_get(:@mapping).each do |(host, path, appl)| 27: next if !host.nil? && !options[:Host].nil? && options[:Host] != host 28: path = '/'+path unless path[0] == // 29: server.register(path, Rack::Handler::Mongrel.new(appl)) 30: end 31: else 32: raise ArgumentError, "first argument should be a Hash or URLMap" 33: end 34: else 35: server.register('/', Rack::Handler::Mongrel.new(app)) 36: end 37: yield server if block_given? 38: server.run.join 39: end
# File lib/rack/handler/mongrel.rb, line 41 41: def self.valid_options 42: { 43: "Host=HOST" => "Hostname to listen on (default: localhost)", 44: "Port=PORT" => "Port to listen on (default: 8080)", 45: "Processors=N" => "Number of concurrent processors to accept (default: 950)", 46: "Timeout=N" => "Time before a request is dropped for inactivity (default: 60)", 47: "Throttle=N" => "Throttle time between socket.accept calls in hundredths of a second (default: 0)", 48: } 49: end
# File lib/rack/handler/mongrel.rb, line 55 55: def process(request, response) 56: env = {}.replace(request.params) 57: env.delete "HTTP_CONTENT_TYPE" 58: env.delete "HTTP_CONTENT_LENGTH" 59: 60: env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" 61: 62: rack_input = request.body || StringIO.new('') 63: rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding) 64: 65: env.update({"rack.version" => Rack::VERSION, 66: "rack.input" => rack_input, 67: "rack.errors" => $stderr, 68: 69: "rack.multithread" => true, 70: "rack.multiprocess" => false, # ??? 71: "rack.run_once" => false, 72: 73: "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http" 74: }) 75: env["QUERY_STRING"] ||= "" 76: 77: status, headers, body = @app.call(env) 78: 79: begin 80: response.status = status.to_i 81: response.send_status(nil) 82: 83: headers.each { |k, vs| 84: vs.split("\n").each { |v| 85: response.header[k] = v 86: } 87: } 88: response.send_header 89: 90: body.each { |part| 91: response.write part 92: response.socket.flush 93: } 94: ensure 95: body.close if body.respond_to? :close 96: end 97: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.