Created
October 10, 2009 02:19
-
-
Save laktek/206529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! It works great.