From a5186af9c8968fe91479770e9cb06d312952958c Mon Sep 17 00:00:00 2001 From: James Bunton Date: Fri, 26 Oct 2007 20:41:53 +1000 Subject: [PATCH] Cleaned up code slightly --- ruby/proxy.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ruby/proxy.rb b/ruby/proxy.rb index f03091d..4eb744b 100755 --- a/ruby/proxy.rb +++ b/ruby/proxy.rb @@ -10,25 +10,25 @@ class NilClass end -def createUrl(url) +def getParams(url) if !ENV["PATH_INFO"].empty? url += ENV["PATH_INFO"] end - if !ENV["QUERY_STRING"].empty? - url += "?" + ENV["QUERY_STRING"] - end + url = URI.parse(url); if url.scheme != "http" raise RuntimeError, "Unsupported scheme: #{url.scheme}" end - return url -end -def createRequest(method, url) path = url.path - if !url.query.empty? - path += "?" + url.query + if !ENV["QUERY_STRING"].empty? + path += "?" + ENV["QUERY_STRING"] end + + return url.host, url.port, path +end + +def createRequest(method, path) if method == "GET" req = Net::HTTP::Get.new(path) elsif method == "POST" @@ -85,10 +85,10 @@ def debug(msg) end def proxyTo(basePath) - url = createUrl(basePath) - req = createRequest(ENV["REQUEST_METHOD"], url) + host, port, path = getParams(basePath) + req = createRequest(ENV["REQUEST_METHOD"], path) insertHeaders(req) - res = doRequest(req, url.host, url.port) + res = doRequest(req, host, port) printResult(res) end -- 2.39.2