diff options
author | Eric Wong <e@80x24.org> | 2015-03-13 23:45:18 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-03-14 02:57:04 +0000 |
commit | 84a393699edfaf9da25fc4de5232468c2b0e2470 (patch) | |
tree | 0202b95e14e206d3c336dde285bf283cf151c691 /extras | |
parent | 404eed25354998f69a56205adc6ea70f3306216f (diff) | |
download | yahns-84a393699edfaf9da25fc4de5232468c2b0e2470.tar.gz |
This is slightly more nginx-style behavior and allows simpler configuration.
Diffstat (limited to 'extras')
-rw-r--r-- | extras/proxy_pass.rb | 24 |
1 files 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) |