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