File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def call(env)
15
15
matcher = get_matcher rackreq . fullpath
16
16
return @app . call ( env ) if matcher . nil?
17
17
18
- uri = matcher . get_uri ( rackreq . fullpath )
18
+ uri = matcher . get_uri ( rackreq . fullpath , env )
19
19
all_opts = @global_options . dup . merge ( matcher . options )
20
20
headers = Rack ::Utils ::HeaderHash . new
21
21
env . each { |key , value |
@@ -86,7 +86,7 @@ def reverse_proxy_options(options)
86
86
end
87
87
88
88
def reverse_proxy matcher , url , opts = { }
89
- raise GenericProxyURI . new ( url ) if matcher . is_a? ( String ) && URI ( url ) . class == URI ::Generic
89
+ raise GenericProxyURI . new ( url ) if matcher . is_a? ( String ) && url . is_a? ( String ) && URI ( url ) . class == URI ::Generic
90
90
@matchers << ReverseProxyMatcher . new ( matcher , url , opts )
91
91
end
92
92
end
@@ -135,12 +135,13 @@ def match?(path)
135
135
match_path ( path ) ? true : false
136
136
end
137
137
138
- def get_uri ( path )
139
- if url =~/\$ \d /
140
- match_path ( path ) . to_a . each_with_index { |m , i | url . gsub! ( "$#{ i . to_s } " , m ) }
141
- URI ( url )
138
+ def get_uri ( path , env )
139
+ _url = ( url . respond_to? ( :call ) ? url . call ( env ) : url )
140
+ if _url =~/\$ \d /
141
+ match_path ( path ) . to_a . each_with_index { |m , i | _url . gsub! ( "$#{ i . to_s } " , m ) }
142
+ URI ( _url )
142
143
else
143
- URI . join ( url , path )
144
+ URI . join ( _url , path )
144
145
end
145
146
end
146
147
def to_s
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ def dummy_app
16
16
def app
17
17
Rack ::ReverseProxy . new ( dummy_app ) do
18
18
reverse_proxy '/test' , 'http://example.com/' , { :preserve_host => true }
19
+ reverse_proxy '/2test' , lambda { 'http://example.com/' }
20
+
19
21
end
20
22
end
21
23
@@ -31,6 +33,12 @@ def app
31
33
last_response . body . should == "Proxied App"
32
34
end
33
35
36
+ it "should proxy requests to a lambda url when a pattern is matched" do
37
+ stub_request ( :get , 'http://example.com/2test' ) . to_return ( { :body => "Proxied App2" } )
38
+ get '/2test'
39
+ last_response . body . should == "Proxied App2"
40
+ end
41
+
34
42
it "the response header should never contain Status" do
35
43
stub_request ( :any , 'example.com/test/stuff' ) . to_return ( :headers => { 'Status' => '200 OK' } )
36
44
get '/test/stuff'
You can’t perform that action at this time.
0 commit comments