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"
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