|
From: <tom...@us...> - 2010-01-29 17:46:06
|
Revision: 2087
http://ndlb.svn.sourceforge.net/ndlb/?rev=2087&view=rev
Author: tombenner
Date: 2010-01-29 17:45:59 +0000 (Fri, 29 Jan 2010)
Log Message:
-----------
Improved the handling of query strings in UtilsController#proxy
Modified Paths:
--------------
portal/ror/plugins/thdl_integration/trunk/app/controllers/thl/utils_controller.rb
Modified: portal/ror/plugins/thdl_integration/trunk/app/controllers/thl/utils_controller.rb
===================================================================
--- portal/ror/plugins/thdl_integration/trunk/app/controllers/thl/utils_controller.rb 2010-01-29 00:59:10 UTC (rev 2086)
+++ portal/ror/plugins/thdl_integration/trunk/app/controllers/thl/utils_controller.rb 2010-01-29 17:45:59 UTC (rev 2087)
@@ -1,13 +1,19 @@
class Thl::UtilsController < ApplicationController
def proxy
+
+ # We want to grab params that are part of the requested URL, but ignore ones that are supplied by Rails
ignored_params = ["proxy_url", "action", "controller"]
url_params = params.reject{|param, val| ignored_params.include?(param) }.collect{ |param, val| param + '=' + CGI.escape(val) }.join('&')
- url = params[:proxy_url].join('/') + '?' + url_params
+ url = params[:proxy_url].join('/')
+ url += '?' + url_params unless url_params.blank?
url = "http://www.thlib.org" + url if url[0,1] == "/"
+
+ # Parse the URL with URI.parse() so we can work with its parts more easily
uri = URI.parse(url)
requested_host = uri.host
headers = {}
+
# Check to see if the request is for a URL on thlib.org or a subdomain; if so, and if
# this is being run on sds[3-8], make the appropriate changes to headers and uri.host
if requested_host =~ /thlib.org/
@@ -17,13 +23,18 @@
uri.host = '127.0.0.1'
end
end
+
# Required for requests without paths (e.g. http://www.google.com)
uri.path = "/" if uri.path.empty?
- request = Net::HTTP::Get.new(uri.path + '?' + uri.query, headers)
+
+ path = uri.query.blank? ? uri.path : uri.path + '?' + uri.query
+ request = Net::HTTP::Get.new(path, headers)
result = Net::HTTP.start(uri.host, uri.port) {|http|
http.request(request)
}
+
render :text => result.body
+
end
end
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|