@@ -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 = { }
9
+ @global_options = { :preserve_host => false }
10
10
instance_eval &b if block_given?
11
11
end
12
12
@@ -16,7 +16,7 @@ def call(env)
16
16
return @app . call ( env ) if matcher . nil?
17
17
18
18
uri = matcher . get_uri ( rackreq . fullpath )
19
- all_opts = matcher . options #TODO: merge with global opts
19
+ all_opts = @global_options . dup . merge ( matcher . options )
20
20
headers = Rack ::Utils ::HeaderHash . new
21
21
env . each { |key , value |
22
22
if key =~ /HTTP_(.*)/
@@ -81,6 +81,10 @@ def create_response_headers http_response
81
81
end
82
82
83
83
84
+ def reverse_proxy_options ( options )
85
+ @global_options = options
86
+ end
87
+
84
88
def reverse_proxy matcher , url , opts = { }
85
89
raise GenericProxyURI . new ( url ) if matcher . is_a? ( String ) && URI ( url ) . class == URI ::Generic
86
90
@matchers << ReverseProxyMatcher . new ( matcher , url , opts )
@@ -121,7 +125,7 @@ class ReverseProxyMatcher
121
125
def initialize ( matching , url , options )
122
126
@matching = matching
123
127
@url = url
124
- @options = { :preserve_host => false } . merge ( options )
128
+ @options = options
125
129
@matching_regexp = matching . kind_of? ( Regexp ) ? matching : /^#{ matching . to_s } /
126
130
end
127
131
0 commit comments