Created
June 18, 2010 21:53
-
-
Save paulclip/444277 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
# tinyproxy.rb | |
# just for the fun of it | |
require 'socket' | |
require 'http-access2' | |
def process_request(conn) | |
verb, uri, protocol = conn.gets.split | |
puts uri | |
http = HTTPAccess2::Client.new() | |
resp = http.get(uri) | |
while HTTP::Status.redirect?(resp.status) | |
puts "redirect" | |
resp = http.get(resp.header['location'][0]) | |
end | |
conn.puts resp.content | |
conn.close | |
end | |
server = TCPServer.new('localhost', 4567) | |
while (conn = server.accept) do | |
Thread.new(conn) do |c| | |
process_request(c) | |
end | |
end | |
</pre> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment