Class | Merb::Rack::Handler::Mongrel |
In: |
merb-core/lib/merb-core/rack/handler/mongrel.rb
|
Parent: | ::Mongrel::HttpHandler |
app<Merb::Rack::Application>: | The app that Mongrel should handle. |
:api: plugin
# File merb-core/lib/merb-core/rack/handler/mongrel.rb, line 53 53: def initialize(app) 54: @app = app 55: end
Runs the server and yields it to a block.
app<Merb::Rack::Application>: | The app that Mongrel should handle. |
options<Hash>: | Options to pass to Mongrel (see below). |
server<Mongrel::HttpServer>: | The server to run. |
:Host<String>: | The hostname on which the app should run. Defaults to "0.0.0.0" |
:Port<Fixnum>: | The port for the app. Defaults to 8080. |
:api: plugin
# File merb-core/lib/merb-core/rack/handler/mongrel.rb, line 36 36: def self.run(app, options={}) 37: @server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0', 38: options[:Port] || 8080) 39: @server.register('/', ::Merb::Rack::Handler::Mongrel.new(app)) 40: yield @server if block_given? 41: @server.run.join 42: end
:api: private
# File merb-core/lib/merb-core/rack/handler/mongrel.rb, line 45 45: def self.stop(block = true) 46: @server.stop 47: end
request<Merb::Request>: | The HTTP request to handle. |
response<HTTPResponse>: | The response object to write response to. |
:api: plugin
# File merb-core/lib/merb-core/rack/handler/mongrel.rb, line 62 62: def process(request, response) 63: env = {}.replace(request.params) 64: env.delete Merb::Const::HTTP_CONTENT_TYPE 65: env.delete Merb::Const::HTTP_CONTENT_LENGTH 66: 67: env[Merb::Const::SCRIPT_NAME] = Merb::Const::EMPTY_STRING if env[Merb::Const::SCRIPT_NAME] == Merb::Const::SLASH 68: 69: env.update({"rack.version" => [0,1], 70: "rack.input" => request.body || StringIO.new(""), 71: "rack.errors" => STDERR, 72: 73: "rack.multithread" => true, 74: "rack.multiprocess" => false, # ??? 75: "rack.run_once" => false, 76: 77: "rack.url_scheme" => "http" 78: }) 79: env[Merb::Const::QUERY_STRING] ||= "" 80: env.delete Merb::Const::PATH_INFO if env[Merb::Const::PATH_INFO] == Merb::Const::EMPTY_STRING 81: 82: status, headers, body = @app.call(env) 83: 84: begin 85: response.status = status.to_i 86: headers.each { |k, vs| 87: vs.each { |v| 88: response.header[k] = v 89: } 90: } 91: 92: body.each { |part| 93: response.body << part 94: } 95: response.finished 96: ensure 97: body.close if body.respond_to? :close 98: end 99: end