X-Git-Url: https://code.delx.au/cgiproxy/blobdiff_plain/b76ed1c2c7ba8016a805e6be96cfd2f471e1527e..80e465ea4142082c2402e597d7630cca6cb96da6:/ruby/proxy.rb diff --git a/ruby/proxy.rb b/ruby/proxy.rb old mode 100755 new mode 100644 index 10002f1..27e5538 --- a/ruby/proxy.rb +++ b/ruby/proxy.rb @@ -23,12 +23,13 @@ def getParams(url) use_ssl = url.scheme == 'https' + filename = url.path path = url.path if !ENV["QUERY_STRING"].empty? path += "?" + ENV["QUERY_STRING"] end - return url.host, url.port, use_ssl, path + return url.host, url.port, use_ssl, filename, path end def createRequest(method, path) @@ -88,17 +89,23 @@ def printResult(res) print res.body end +def writeFile(res, filename, outputDir) + filename = filename.split("/")[-1] + File.open("#{outputDir}/#{filename}", 'w') {|f| f.write(res.body) } +end + def debug(msg) File.open("/tmp/debuglog.txt", "a") { |f| f << Time.new.to_s + " " + msg + "\n" } end -def proxyTo(basePath, ffHeader=True) - host, port, use_ssl, path = getParams(basePath) +def proxyTo(basePath, ffHeader=True, outputDir=None) + host, port, use_ssl, filename, path = getParams(basePath) req = createRequest(ENV["REQUEST_METHOD"], path) insertHeaders(req, ffHeader) res = doRequest(req, host, port, use_ssl) + writeFile(res, filename, outputDir) printResult(res) end