From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, T_RP_MATCHES_RCVD shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id BA1E91F5D6 for ; Sat, 14 Mar 2015 03:18:02 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 1/3] extras/proxy_pass: implicit $fullpath expansion for upstreams Date: Sat, 14 Mar 2015 03:17:56 +0000 Message-Id: <1426303078-4525-2-git-send-email-e@80x24.org> In-Reply-To: <1426303078-4525-1-git-send-email-e@80x24.org> References: <1426303078-4525-1-git-send-email-e@80x24.org> List-Id: 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