I'm having to implement a proxy on a Rails 3.1 app to overcome some cross-domain JS issues.
So far I have it retrieving web page text source seemingly right, however it commonly misses images (perhaps relative paths?) in the page and then when I direct it with an absolute path to an image it will show the ascii encoding of the image rather than the image itself, I think for obvious reasons from the code for someone familiar with the topic.
I was hopeful that someone would be able to revise the following code so as to work also properly with an image proxy situation:
proxy_controller.rb:
class ProxyController < ApplicationController
def get
url = URI.parse(params["url"])
result = Net::HTTP.get_response(url)
render :text => result.body
end
end
routes.rb:
get "proxy" => "proxy#get", :as => "proxy"
Calling it via:
http://<my_dev_server>/proxy?url=http://<somedomain.tld>/path/to/page/images/image.jpg
or
http://<my_dev_server>/proxy?url=http://<somedomain.tld>/path/to/page
instead of render, use send_data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With