We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: OUTDATED mirror of Rack's darcs repository, use github.com/chneukirchen/rack
Homepage: http://rack.rubyforge.org/
Clone URL: git://github.com/chneukirchen/rack-mirror.git
Let Rack::Builder#use accept blocks

Contributed by Corey Jewett.

darcs-hash:20080224175153-4fc50-92205606f938818e1a6e4e8d702ef3083f5e0c5a.g
z
chneukirchen (author)
Sun Feb 24 09:51:00 -0800 2008
commit  0639994b6b95ab737d5f86a97b110fa63a61dab3
tree    5e492a2e1aefac53b7ef6859fcd185c048097952
parent  443896e2e9bcf46a3ba05cd085c0837c8d6a4c82
...
22
23
24
25
26
 
 
 
 
 
 
27
28
29
...
22
23
24
 
 
25
26
27
28
29
30
31
32
33
0
@@ -22,8 +22,12 @@ module Rack
0
       instance_eval(&block)
0
     end
0
 
0
- def use(middleware, *args)
0
- @ins << lambda { |app| middleware.new(app, *args) }
0
+ def use(middleware, *args, &block)
0
+ @ins << if block_given?
0
+ lambda { |app| middleware.new(app, *args, &block) }
0
+ else
0
+ lambda { |app| middleware.new(app, *args) }
0
+ end
0
     end
0
 
0
     def run(app)
...
25
26
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
0
@@ -25,4 +25,26 @@ context "Rack::Builder" do
0
     Rack::MockRequest.new(app).get("/").should.be.server_error
0
     Rack::MockRequest.new(app).get("/").should.be.server_error
0
   end
0
+
0
+ specify "supports blocks on use" do
0
+ app = Rack::Builder.new do
0
+ use Rack::ShowExceptions
0
+ use Rack::Auth::Basic do |username, password|
0
+ 'secret' == password
0
+ end
0
+
0
+ run lambda { |env| [200, {}, 'Hi Boss'] }
0
+ end
0
+
0
+ response = Rack::MockRequest.new(app).get("/")
0
+ response.should.be.client_error
0
+ response.status.should.equal 401
0
+
0
+ # with auth...
0
+ response = Rack::MockRequest.new(app).get("/",
0
+ 'HTTP_AUTHORIZATION' => 'Basic ' + ["joe:secret"].pack("m*"))
0
+ response.status.should.equal 200
0
+ response.body.to_s.should.equal 'Hi Boss'
0
+ end
0
+
0
 end

Comments

    No one has commented yet.