Class: Rack::ReverseProxyMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/reverse_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matching, url, options) ⇒ ReverseProxyMatcher

Returns a new instance of ReverseProxyMatcher.



144
145
146
147
148
149
# File 'lib/rack/reverse_proxy.rb', line 144

def initialize(matching,url,options)
  @matching=matching
  @url=url
  @options=options
  @matching_regexp= matching.kind_of?(Regexp) ? matching : /^#{matching.to_s}/
end

Instance Attribute Details

#matchingObject (readonly)

Returns the value of attribute matching.



151
152
153
# File 'lib/rack/reverse_proxy.rb', line 151

def matching
  @matching
end

#matching_regexpObject (readonly)

Returns the value of attribute matching_regexp.



151
152
153
# File 'lib/rack/reverse_proxy.rb', line 151

def matching_regexp
  @matching_regexp
end

#optionsObject (readonly)

Returns the value of attribute options.



151
152
153
# File 'lib/rack/reverse_proxy.rb', line 151

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



151
152
153
# File 'lib/rack/reverse_proxy.rb', line 151

def url
  @url
end

Instance Method Details

#get_uri(path, env) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'lib/rack/reverse_proxy.rb', line 157

def get_uri(path,env)
  _url=(url.respond_to?(:call) ? url.call(env) : url.clone)
  if _url =~/\$\d/
    match_path(path).to_a.each_with_index { |m, i| _url.gsub!("$#{i.to_s}", m) }
    URI(_url)
  else
    URI.join(_url, path)
  end
end

#match?(path) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/rack/reverse_proxy.rb', line 153

def match?(path)
  match_path(path) ? true : false
end

#to_sObject



166
167
168
# File 'lib/rack/reverse_proxy.rb', line 166

def to_s
  %Q("#{matching.to_s}" => "#{url}")
end