Class: Rack::ReverseProxyMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, url = nil, options = {}) ⇒ ReverseProxyMatcher

Returns a new instance of ReverseProxyMatcher.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/rack/reverse_proxy_matcher.rb', line 3

def initialize(matcher, url=nil, options={})
  @default_url=url
  @url=url
  @options=options

  if matcher.kind_of?(String)
    @matcher = /^#{matcher.to_s}/
  elsif matcher.respond_to?(:match)
    @matcher = matcher
  else
    raise "Invalid Matcher for reverse_proxy"
  end
end

Instance Attribute Details

#default_urlObject (readonly)

Returns the value of attribute default_url.



17
18
19
# File 'lib/rack/reverse_proxy_matcher.rb', line 17

def default_url
  @default_url
end

#matcherObject (readonly)

Returns the value of attribute matcher.



17
18
19
# File 'lib/rack/reverse_proxy_matcher.rb', line 17

def matcher
  @matcher
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/rack/reverse_proxy_matcher.rb', line 17

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



17
18
19
# File 'lib/rack/reverse_proxy_matcher.rb', line 17

def url
  @url
end

Instance Method Details

#get_uri(path, env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/rack/reverse_proxy_matcher.rb', line 23

def get_uri(path,env)
  return nil if url.nil?
  _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
    default_url.nil? ? URI.parse(_url) : URI.join(_url, path)
  end
end

#match?(path, *args) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rack/reverse_proxy_matcher.rb', line 19

def match?(path, *args)
  match_path(path, *args) ? true : false
end

#to_sObject



34
35
36
# File 'lib/rack/reverse_proxy_matcher.rb', line 34

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