Skip to content

Commit d69923e

Browse files
committed
Allow matchers to return nil and continue onto the original rack app
1 parent 93ec24d commit d69923e

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/rack/reverse_proxy.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def call(env)
3434

3535
def proxy(env, source_request, matcher)
3636
uri = matcher.get_uri(source_request.fullpath,env)
37+
if uri.nil?
38+
return @app.call(env)
39+
end
3740
options = @global_options.dup.merge(matcher.options)
3841

3942
# Initialize request

lib/rack/reverse_proxy_matcher.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def match?(path, *args)
2121
end
2222

2323
def get_uri(path,env)
24+
return nil if url.nil?
2425
_url=(url.respond_to?(:call) ? url.call(env) : url.clone)
2526
if _url =~/\$\d/
2627
match_path(path).to_a.each_with_index { |m, i| _url.gsub!("$#{i.to_s}", m) }

spec/rack/reverse_proxy_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ def self.match(path, headers, rackreq)
279279
def url(path)
280280
if rackreq.params["user"] == 'omer'
281281
'http://users-example.com' + path
282-
else
283-
'http://example.com' + path
284282
end
285283
end
286284
end
@@ -298,10 +296,9 @@ def app
298296
end
299297

300298
it "should proxy requests when a pattern is matched" do
301-
stub_request(:get, 'http://example.com/test?user=mark').to_return({:body => "Proxied App"})
302299
stub_request(:get, 'http://users-example.com/users?user=omer').to_return({:body => "User App"})
303300
get '/test', user: "mark"
304-
last_response.body.should == "Proxied App"
301+
last_response.body.should == "Dummy App"
305302
get '/users', user: 'omer'
306303
last_response.body.should == "User App"
307304
end

0 commit comments

Comments
 (0)