Created
December 1, 2010 14:49
-
-
Save na9da/723577 to your computer and use it in GitHub Desktop.
Test & patch for async routes with condition clauses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AsyncTest < Sinatra::Base | |
register Sinatra::Async | |
aget '/', :agent => /foo/ do | |
body "Agent foo" | |
end | |
aget '/', :agent => /bar/ do | |
body "Agent bar" | |
end | |
end | |
AsyncTest.run! | |
# curl -H'User-agent: bar' http://localhost:4567/ | |
# > Agent bar | |
# curl -H'User-agent: foo' http://localhost:4567/ | |
# > Agent bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/sinatra/async.rb b/lib/sinatra/async.rb | |
index 2701fee..cbf900f 100644 | |
--- a/lib/sinatra/async.rb | |
+++ b/lib/sinatra/async.rb | |
@@ -59,7 +59,7 @@ module Sinatra #:nodoc: | |
private | |
def aroute(verb, path, opts = {}, &block) #:nodoc: | |
- method = "A#{verb} #{path}".to_sym | |
+ method = "A#{verb} #{path}#{opts.hash}".to_sym | |
define_method method, &block | |
route(verb, path, opts) do |*bargs| | |
@@ -159,4 +159,4 @@ module Sinatra #:nodoc: | |
app.helpers Helpers | |
end | |
end | |
-end | |
\ No newline at end of file | |
+end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment