Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class HideController < ApplicationController

  # SEE http://wiki.rubyonrails.org/rails/pages/HowToRenderProxiedPages
  # AND http://wiki.rubyonrails.org/rails/pages/HowToRouteGenericURLsToAController

  after_filter :change_urls

  # REST: GET /
  def index
    url = URI.parse(params[:myurl])
    method = request.request_method
    data   = request.parameters

    @myhost = url.host
    @myresponse = Net::HTTP.start(url.host,url.port) { |x|
      x.send(method,url.path,data)
    }

    render :text => @myresponse.body

  end

  private
  def change_urls

    # ed ora qualcosa di veramente grezzo
    @myresponse.body.gsub!(/src="(.*?)"/) { |x|
      newurl = "src=\"" + "http://0.0.0.0:3000/http://" + @myhost + $1 + "\""
    }

  end

end