Skip to content

Instantly share code, notes, and snippets.

@laktek
Created October 10, 2009 02:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save laktek/206529 to your computer and use it in GitHub Desktop.
Save laktek/206529 to your computer and use it in GitHub Desktop.
require 'net/http'
class ServerProxy
def self.call(env)
if env["PATH_INFO"] =~ /^\/server_proxy/
request = Rack::Request.new(env)
params = request.params
Net::HTTP.start(params["service_url"]) {|http|
req = Net::HTTP::Get.new(params["service_path"])
req.basic_auth params['username'], params['password']
response = http.request(req)
@server_response = response.body
@server_code = response.code
@server_content_type = response.content_type
}
[@server_code, {"Content-Type" => @server_content_type}, [@server_response]]
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
end
end
end
@dsabanin
Copy link

Thank you! It works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment