- @bot.httputil.get_response(url) { |response|
- case response
- when Net::HTTPSuccess
- extra = String.new
-
- if response['content-type'] =~ /^text\//
-
- title = String.new
-
- # since the content is 'text/*' and is small enough to
- # be a webpage, retrieve the title from the page
- debug "+ getting #{url.request_uri}"
-
- # we act differently depending on whether we want the first par or not:
- # in the first case we download the initial part and the parse it; in the second
- # case we only download as much as we need to find the title
- if @bot.config['url.first_par']
- partial = response.partial_body(@bot.config['http.info_bytes'])
- first_par = Utils.ircify_first_html_par(partial)
- extra << "\n#{LINK_INFO} text: #{first_par}" unless first_par.empty?
- title = get_title_from_html(partial)
- if title
- return "title: #{title}#{extra}"
- end
- else
- response.partial_body(@bot.config['http.info_bytes']) { |part|
- title = get_title_from_html(part)
- return "title: #{title}" if title
- }
- end
- # if nothing was found, provide more basic info
- end
+ range = @bot.config['http.info_bytes']
+ response = @bot.httputil.get_response(url, :range => "bytes=0-#{range}")
+ if response.code != "206" && response.code != "200"
+ return "Error getting link (#{response.code} - #{response.message})"
+ end
+ extra = String.new