Skip to content

Instantly share code, notes, and snippets.

@paulclip
Created June 18, 2010 21:53
Show Gist options
  • Save paulclip/444277 to your computer and use it in GitHub Desktop.
Save paulclip/444277 to your computer and use it in GitHub Desktop.
# 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