From: Craig Moran Date: 2005-04-25T22:05:49+09:00 Subject: Re: Proxy Server troubles I am behind a proxy server at work, yet got this to work. I commented out your Net::HTTP.new line and added what I believe to be the Proxy equivalent. Then I set Mozilla Firefox's proxy to be localhost:8080. NOTE: I do not have the ability to use another machine to test as I am very restricted with net access here. I launched slashdot.org and monitored the proxy.rb window while all of the HTML flew by. It came up and rendered properly in the browser. I am on Windows 2000 C:\>ruby -v ruby 1.8.2 (2004-12-25) [i386-mswin32] Here's the code. Hope it helps: require 'socket' require 'net/http' local_host = 'localhost' local_port = 8080 host = 'slashdot.org' server = TCPServer.new(local_host, local_port) while true Thread.start(server.accept) do |s| data = '' while s.gets && !$_.nil? data += $_ break if $_ == "\r\n" || $_ == "\n" end p "====Received: #{data}" # net = Net::HTTP.new(host,80) net = Net::HTTP::Proxy("proxy", "80").start(host) response = net.get('/') s << "HTTP/#{response.http_version}#{response.code}/#{response.message} \r\n" p "====Got back" response.each_header do |key,value| tmp = key + ": " + value + "\r\n" p tmp s << tmp end p response.body s << "\r\n" << response.body s.close # We're done with this request, bring on the next. end end On 4/21/05, Tanner Burson wrote: > I've been working on a proxy server implementation for a project idea > I have. But I've found that it only seems to work on certain pages, > and not on others. I've distilled the problem down to a simple > implementation, but it still occurs. The code below will return a > (mostly) correct website if pointed at 'www.msn.com' but if pointed at > say 'slashdot.org' the browser refuses to display it, in both cases > the page is loaded correctly. If anyone has any ideas I'd really > appreciate it. > > ===proxy.rb > > require 'socket' > require 'net/http' > local_host = '192.168.0.6' > local_port = 8080 > > host = 'slashdot.org' > server = TCPServer.new(local_host,local_port) > while true > Thread.start(server.accept) do |s| > data = '' > while s.gets && !$_.nil? > data += $_ > break if $_ == "\r\n" || $_ == "\n" > end > p "====Received: #{data}" > net = Net::HTTP.new(host,80) > response = net.get('/') > s << "HTTP/#{response.http_version} > #{response.code}/#{response.message} \r\n" > p "====Got back" > response.each_header do |key,value| > tmp = key + ": " + value + "\r\n" > p tmp > s << tmp > end > p response.body > s << "\r\n" << response.body > s.close # We're done with this request, bring on the next. > end > end > > ====end > -- > ===Tanner Burson=== > tanner.burson@gmail.com > http://tannerburson.com <---Might even work one day... > >