@@ -15,9 +15,10 @@ class Redirect
1515 </ html >
1616 HTML
1717
18- def initialize ( env , host , options = { } )
18+ def initialize ( env , host = nil , options = { } , & block )
1919 self . env = env
20- self . host = host
20+ self . default_host = host
21+ self . block = block
2122 self . ignore = Array ( options [ :ignore ] )
2223 self . conditions = Array ( options [ :if ] )
2324 self . cache_control = options [ :cache_control ]
@@ -35,7 +36,8 @@ def response
3536 protected
3637
3738 attr_accessor :env
38- attr_accessor :host
39+ attr_accessor :default_host
40+ attr_accessor :block
3941 attr_accessor :ignore
4042 attr_accessor :conditions
4143 attr_accessor :cache_control
@@ -53,6 +55,12 @@ def any_match?(patterns, request_uri)
5355 }
5456 end
5557
58+ def enabled?
59+ return true if conditions . empty?
60+
61+ any_match? ( conditions , request_uri )
62+ end
63+
5664 def headers
5765 {
5866 'cache-control' => cache_control ,
@@ -61,10 +69,9 @@ def headers
6169 } . reject { |_ , value | !value }
6270 end
6371
64- def enabled?
65- return true if conditions . empty?
66-
67- any_match? ( conditions , request_uri )
72+ def host
73+ return @host if defined? ( @host )
74+ @host = block && block . call ( env ) || default_host
6875 end
6976
7077 def ignored?
0 commit comments