File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ class ReverseProxy
6
6
def initialize ( app = nil , &b )
7
7
@app = app || lambda { [ 404 , [ ] , [ ] ] }
8
8
@matchers = [ ]
9
- @global_options = { :preserve_host => false }
9
+ @global_options = { :preserve_host => false , :matching => :all }
10
10
instance_eval &b if block_given?
11
11
end
12
12
@@ -63,7 +63,7 @@ def get_matcher path
63
63
64
64
if matches . length < 1
65
65
nil
66
- elsif matches . length > 1
66
+ elsif matches . length > 1 && @global_options [ :matching ] != :first
67
67
raise AmbiguousProxyMatch . new ( path , matches )
68
68
else
69
69
matches . first
Original file line number Diff line number Diff line change @@ -77,9 +77,10 @@ def app
77
77
end
78
78
end
79
79
80
- describe "with ambiguous routes" do
80
+ describe "with ambiguous routes and all matching " do
81
81
def app
82
82
Rack ::ReverseProxy . new ( dummy_app ) do
83
+ reverse_proxy_options :matching => :all
83
84
reverse_proxy '/test' , 'http://example.com/'
84
85
reverse_proxy /^\/ test/ , 'http://example.com/'
85
86
end
@@ -90,6 +91,22 @@ def app
90
91
end
91
92
end
92
93
94
+ describe "with ambiguous routes and first matching" do
95
+ def app
96
+ Rack ::ReverseProxy . new ( dummy_app ) do
97
+ reverse_proxy_options :matching => :first
98
+ reverse_proxy '/test' , 'http://example1.com/'
99
+ reverse_proxy /^\/ test/ , 'http://example2.com/'
100
+ end
101
+ end
102
+
103
+ it "should throw an exception" do
104
+ stub_request ( :get , 'http://example1.com/test' ) . to_return ( { :body => "Proxied App" } )
105
+ get '/test'
106
+ last_response . body . should == "Proxied App"
107
+ end
108
+ end
109
+
93
110
describe "with a route as a regular expression" do
94
111
def app
95
112
Rack ::ReverseProxy . new ( dummy_app ) do
You can’t perform that action at this time.
0 commit comments