Class Rack::Handler::Mongrel
In: lib/rack/handler/mongrel.rb
Parent: ::Mongrel::HttpHandler

Methods

new   process   run  

Public Class methods

[Source]

    # File lib/rack/handler/mongrel.rb, line 35
35:       def initialize(app)
36:         @app = app
37:       end

[Source]

    # File lib/rack/handler/mongrel.rb, line 7
 7:       def self.run(app, options={})
 8:         server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0',
 9:                                            options[:Port] || 8080)
10:         # Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
11:         # Use is similar to #run, replacing the app argument with a hash of 
12:         # { path=>app, ... } or an instance of Rack::URLMap.
13:         if options[:map]
14:           if app.is_a? Hash
15:             app.each do |path, appl|
16:               path = '/'+path unless path[0] == ?/
17:               server.register(path, Rack::Handler::Mongrel.new(appl))
18:             end
19:           elsif app.is_a? URLMap
20:             app.instance_variable_get(:@mapping).each do |(host, path, appl)|
21:              next if !host.nil? && !options[:Host].nil? && options[:Host] != host
22:              path = '/'+path unless path[0] == ?/
23:              server.register(path, Rack::Handler::Mongrel.new(appl))
24:             end
25:           else
26:             raise ArgumentError, "first argument should be a Hash or URLMap"
27:           end
28:         else
29:           server.register('/', Rack::Handler::Mongrel.new(app))
30:         end
31:         yield server  if block_given?
32:         server.run.join
33:       end

Public Instance methods

[Source]

    # File lib/rack/handler/mongrel.rb, line 39
39:       def process(request, response)
40:         env = {}.replace(request.params)
41:         env.delete "HTTP_CONTENT_TYPE"
42:         env.delete "HTTP_CONTENT_LENGTH"
43: 
44:         env["SCRIPT_NAME"] = ""  if env["SCRIPT_NAME"] == "/"
45: 
46:         env.update({"rack.version" => [0,1],
47:                      "rack.input" => request.body || StringIO.new(""),
48:                      "rack.errors" => STDERR,
49: 
50:                      "rack.multithread" => true,
51:                      "rack.multiprocess" => false, # ???
52:                      "rack.run_once" => false,
53: 
54:                      "rack.url_scheme" => "http",
55:                    })
56:         env["QUERY_STRING"] ||= ""
57:         env.delete "PATH_INFO"  if env["PATH_INFO"] == ""
58: 
59:         status, headers, body = @app.call(env)
60: 
61:         begin
62:           response.status = status.to_i
63:           response.send_status(nil)
64: 
65:           headers.each { |k, vs|
66:             vs.each { |v|
67:               response.header[k] = v
68:             }
69:           }
70:           response.send_header
71: 
72:           body.each { |part|
73:             response.write part
74:             response.socket.flush
75:           }
76:         ensure
77:           body.close  if body.respond_to? :close
78:         end
79:       end

[Validate]