Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make Rack::Handler::*.run yield the server for further configuration

darcs-hash:20070515154342-4fc50-159cfb0db624ad62ec611c34aa7df1e435822565.gz
  • Loading branch information...
commit c17f371c05ca1881b2d43eba34f8dd65eefbfa8f 1 parent a7d2cb6
@chneukirchen chneukirchen authored
View
3  lib/rack/handler/mongrel.rb
@@ -4,10 +4,11 @@
module Rack
module Handler
class Mongrel < ::Mongrel::HttpHandler
- def self.run(app, options)
+ def self.run(app, options={})
server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0',
options[:Port] || 8080)
server.register('/', Rack::Handler::Mongrel.new(app))
+ yield server
server.run.join
end
View
1  lib/rack/handler/webrick.rb
@@ -8,6 +8,7 @@ def self.run(app, options={})
server = ::WEBrick::HTTPServer.new(options)
server.mount "/", Rack::Handler::WEBrick, app
trap(:INT) { server.shutdown }
+ yield server
server.start
end
View
12 test/spec_rack_mongrel.rb
@@ -81,6 +81,18 @@
response["rack.url_scheme"].should.equal "http"
end
+ specify "should provide a .run" do
+ block_ran = false
+ catch(:done) {
+ Rack::Handler::Mongrel.run(lambda {}, {:Port => 9211}) { |server|
+ block_ran = true
+ server.should.be.kind_of Mongrel::HttpServer
+ throw :done
+ }
+ }
+ block_ran.should.be true
+ end
+
teardown do
@acc.raise Mongrel::StopServer
end
View
17 test/spec_rack_webrick.rb
@@ -83,6 +83,23 @@
response["rack.url_scheme"].should.equal "http"
end
+ specify "should provide a .run" do
+ block_ran = false
+ catch(:done) {
+ Rack::Handler::WEBrick.run(lambda {},
+ {:Port => 9210,
+ :Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
+ :AccessLog => []}) { |server|
+ block_ran = true
+ server.should.be.kind_of WEBrick::HTTPServer
+ @s = server
+ throw :done
+ }
+ }
+ block_ran.should.be true
+ @s.shutdown
+ end
+
teardown do
@server.shutdown
end
Please sign in to comment.
Something went wrong with that request. Please try again.