class Rack::ReverseProxyMatcher

Attributes

default_url[R]
matcher[R]
options[R]
url[R]

Public Class Methods

new(matcher,url=nil,options) click to toggle source
# File vendor/rack-reverse-proxy/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

Public Instance Methods

get_uri(path,env) click to toggle source
# File vendor/rack-reverse-proxy/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) click to toggle source
# File vendor/rack-reverse-proxy/lib/rack/reverse_proxy_matcher.rb, line 19
def match?(path, *args)
  match_path(path, *args) ? true : false
end
to_s() click to toggle source
# File vendor/rack-reverse-proxy/lib/rack/reverse_proxy_matcher.rb, line 34
def to_s
  %Q("#{matcher.to_s}" => "#{url}")
end

Private Instance Methods

match_path(path, *args) click to toggle source
# File vendor/rack-reverse-proxy/lib/rack/reverse_proxy_matcher.rb, line 39
def match_path(path, *args)
  headers = args[0]
  rackreq = args[1]
  arity = matcher.method(:match).arity
  if arity == -1
    match = matcher.match(path)
  else
    params = [path, (@options[:accept_headers] ? headers : nil), rackreq]
    match = matcher.match(*params[0..(arity - 1)])
  end
  @url = match.url(path) if match && default_url.nil?
  match
end