From: Bigmac Turdsplash Date: 2012-01-14T05:30:02+09:00 Subject: Re: Http proxy, string chomp error is nil? Tim Roberts wrote in post #1040307: > Bigmac Turdsplash wrote: >> >>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... > > Your goal is slimy. > >>send_data_to_client response.sub(""," Hellow world >>advertisement") >> >>this works, but the page loads improperly... > > The tag lives in the <head> part of the page. There isn't > supposed > to be anything renderable in the <head> part. You should be looking for > the <body> tag, and insert your slime just after that. If there isn't > one, > then just shove your slime as the very first thing. > >>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... > > You do need to update Content-Length. Ok, i see, with some testing i have been successful with modifying content-length and adding data... i was doing this in the wrong order, my algorithm will find the packet that includes content-length and also includes <body> i have been testing with alert("hello world")... so, i have been replacing strings like <body> <head> <title> <script> etc... i would modify them like this send response.sub("<body>", "<body>xxxxx).sub(cont_length,cont_length+5) so, lets say on one page there are 5 packets that include c-length and also include <body>... then there would be 5 alert messages displayed when the page loads... or, like above was said, what if <body> does not exist... i would like to 'shove my slime as the first thing" but i dont see a control point. how do i know when its the beginning and the end of a page request... there might be 1 or 30 GET request for one page... -- Posted via http://www.ruby-forum.com/.