This is slightly more nginx-style behavior and allows simpler configuration. --- extras/proxy_pass.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/extras/proxy_pass.rb b/extras/proxy_pass.rb index 15cbae5..d435ebe 100644 --- a/extras/proxy_pass.rb +++ b/extras/proxy_pass.rb @@ -112,25 +112,31 @@ class ProxyPass # :nodoc: def initialize(dest, timeout = 5) case dest - when %r{\Ahttp://([^/]+)(/.*)\z} + when %r{\Ahttp://([^/]+)(/.*)?\z} path = $2 host, port = $1.split(':') @sockaddr = Socket.sockaddr_in(port || 80, host) - - # methods from Rack::Request we want: - allow = %w(fullpath host_with_port host port url path) - @path = path - want = path.scan(/\$(\w+)/).flatten! || [] - diff = want - allow - diff.empty? or - raise ArgumentError, "vars not allowed: #{diff.uniq.join(' ')}" else raise ArgumentError, "destination must be an HTTP URL" end + init_path_vars(path) @pool = ConnPool.new @timeout = timeout end + def init_path_vars(path) + path ||= '$(fullpath)' + # methods from Rack::Request we want: + allow = %w(fullpath host_with_port host port url path) + want = path.scan(/\$(\w+)/).flatten! || [] + diff = want - allow + diff.empty? or + raise ArgumentError, "vars not allowed: #{diff.uniq.join(' ')}" + + # kill leading slash just in case... + @path = path.gsub(%r{\A/(\$(?:fullpath|path))}, '\1') + end + def call(env) request_method = env['REQUEST_METHOD'] req = Rack::Request.new(env) -- EW