def do_request(url)
req = []
req << "GET #{url.request_uri} HTTP/1.0"
req << "Host: #{url.host}"
req << "User-Agent: RubyCrawl"
req << ""
req << ""
req = req.join "\r\n"
puts req
begin
s = TCPSocket.new url.host, url.port
s.write req
s.flush
response = s.read
ensure
s.close unless s.nil?
end
headers, body = response.split(/\r\n\r\n/)
headers = headers.split(/\r\n/)
status = headers.shift
headers = Hash[*headers.map { |h| h.split ': ', 2 }.flatten]
puts status
case status
when / 302 / then
body = "href=\"#{headers['Location']}\""
when / 500 / then
body = "href=\"#{@start_url}\""
end
return body
end