Permalink
Browse files

async server support

  • Loading branch information...
1 parent 4de82c2 commit aeda5e2f404606371f73c43a2b9c4c34b4c57a91 @rkh committed Feb 15, 2010
Showing with 51 additions and 5 deletions.
  1. +19 −1 README.md
  2. +7 −0 lib/sinatra/more_server.rb
  3. +25 −4 spec/sinatra/more_server_spec.rb
View
@@ -1,5 +1,5 @@
Sinatra::MoreServer
-=======================
+===================
Adds support for more web servers to [Sinatra](http://sinatrarb.com)::Base#run!.
(Read: The server used when running `ruby yourfile.rb`. This has no effect rackup and akin.)
@@ -42,3 +42,21 @@ Or in your own subclass:
class Foo < Sinatra::Base
register Sinatra::MoreServer
end
+
+Async only, please!
+-------------------
+
+You use `async.callback`? Maybe via a library like [async\_sinatra](http://github.com/raggi/async_sinatra)
+or [pusher](http://github.com/macournoyer/pusher)? Then you might want to make sure we only use a server
+that supports it:
+
+ require "sinatra"
+ require "sinatra/more_server"
+
+ configure do
+ has_async_callback!
+ end
+
+As mentioned above, this will only have effect on running your script directly. However, in any other case,
+you will choose your server manually, anyway. (Hint: As far as I know, only thin- and unicorn-based implementations
+support async.callback at the moment.)
@@ -6,14 +6,21 @@ module MoreServer
autoload :Unicorn, "sinatra/more_server/unicorn"
autoload :Rainbows, "sinatra/more_server/rainbows"
autoload :Zbatery, "sinatra/more_server/zbatery"
+
def self.registered(klass)
::Rack::Handler.register "unicorn", "::Sinatra::MoreServer::Unicorn"
::Rack::Handler.register "rainbows", "::Sinatra::MoreServer::Rainbows"
::Rack::Handler.register "zbatery", "::Sinatra::MoreServer::Zbatery"
::Rack::Handler.register "ebb", "::Rack::Handler::Ebb"
::Rack::Handler.autoload :Ebb, "ebb"
klass.server += ["ebb", "zbatery", "rainbows", "unicorn"]
+ klass.set :async_server, ["thin", "zbatery", "rainbows", "unicorn"]
+ end
+
+ def has_async_callback!
+ set :server, async_server
end
+
end
register MoreServer
@@ -2,7 +2,28 @@
describe Sinatra::MoreServer do
before { app :MoreServer }
- it("should offer unicorn") { app.server.should include("unicorn") }
- it("should offer rainbows") { app.server.should include("rainbows") }
- it("should offer ebb") { app.server.should include("ebb") }
-end
+
+ describe "additional server" do
+ it("should offer unicorn") { app.server.should include("unicorn") }
+ it("should offer rainbows") { app.server.should include("rainbows") }
+ it("should offer zbatery") { app.server.should include("zbatery") }
+ it("should offer ebb") { app.server.should include("ebb") }
+ end
+
+ describe "async_server" do
+ it("should not offer ebb as an async server") { app.async_server.should_not include("ebb") }
+ it("should not offer mongrel as an async server") { app.async_server.should_not include("mongrel") }
+ it("should not offer webrick as an async server") { app.async_server.should_not include("webrick") }
+
+ it("should offer thin as an async server") { app.async_server.should include("thin") }
+ it("should offer unicorn as an async server") { app.async_server.should include("unicorn") }
+ it("should offer rainbows as an async server") { app.async_server.should include("rainbows") }
+ it("should offer zbatery as an async server") { app.async_server.should include("zbatery") }
+
+ it "uses async_server instead of server when async support is requested" do
+ app.has_async_callback!
+ app.server.should == app.async_server
+ end
+ end
+
+end

0 comments on commit aeda5e2

Please sign in to comment.