From: Bigmac Turdsplash Date: 2012-01-10T14:31:20+09:00 Subject: Re: Http proxy, string chomp error is nil? Tim Roberts wrote in post #1040037: > Bigmac Turdsplash wrote: >> >>im building a proxy, im having a problem with processing the get request >>i recive from the client. >>... >>this works every time in irb testing, but is inconsistent when my script >>is running, the proxy works 90% of the time. when www.yahoo.com is >>requested the script crashes with Host nil error but when yahoo.com is >>request the script works fine... >>... >>host = header.to_a[1].chomp[6..-1] => nil > > Do you realize that the headers in an HTTP request can come in any > order? > There is absolutely no guarantee that Host: will be first. You're > relying > on that assumption. I figured this out after testing a few browsers... here is my little hack for scanning threw a header... ping = finger.index("Host:") pong = finger.index("\n",ping) host = finger[ping..pong].gsub("Host:","") So, i have a stable proxy running, My goal is to place at the top of every page a banner or advertisement... send_data_to_client response.sub(""," Hellow world advertisement") this works, but the page loads improperly... so i tried to change the content-length of the packet to zero... I also tried to increase the size of content-length to make room for my banner... so far, the page fails to load properly... I need more ideas! -- Posted via http://www.ruby-forum.com/.