<commit_before>=begin
  $Id$

                  Arachni
  Copyright (c) 2010 <NAME> <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end
require 'rubygems'
require 'anemone'

#
# Overides Anemone's HTTP class method refresh_connection( url )
# adding proxy support
#
# @author: Anastasios "Zapotek" Laskos
#                                      <<EMAIL>>
#                                      <<EMAIL>>
# @version: 0.1-pre
#
class Anemone::HTTP

    def refresh_connection( url )

        http = Net::HTTP.new( url.host, url.port,
        @opts[:proxy_addr], @opts[:proxy_port],
        @opts[:proxy_user], @opts[:proxy_pass] )

        if url.scheme == 'https'
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end

        @connections[url.host][url.port] = http.start
    end

end<commit_msg>added get_response( ): upped the retry counter to 7 and generalized exception handling<commit_after>=begin
  $Id$

                  Arachni
  Copyright (c) 2010 <NAME> <<EMAIL>>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end
require 'rubygems'
require 'anemone'

#
# Overides Anemone's HTTP class methods:
#  o refresh_connection( ): added proxy support
#  o get_response( ): upped the retry counter to 7 and generalized exception handling
#
# @author: Anastasios "Zapotek" Laskos
#                                      <<EMAIL>>
#                                      <<EMAIL>>
# @version: 0.1-pre
#
class Anemone::HTTP

    include Arachni::UI::Output

    def refresh_connection( url )

        http = Net::HTTP.new( url.host, url.port,
        @opts[:proxy_addr], @opts[:proxy_port],
        @opts[:proxy_user], @opts[:proxy_pass] )

        if url.scheme == 'https'
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        end

        @connections[url.host][url.port] = http.start
    end

    #
    # Get an HTTPResponse for *url*, sending the appropriate User-Agent string
    #
    def get_response(url, referer = nil)
        full_path = url.query.nil? ? url.path : "#{url.path}?#{url.query}"

        opts = {}
        opts['User-Agent'] = user_agent if user_agent
        opts['Referer'] = referer.to_s if referer
        opts['Cookie'] = @cookie_store.to_s unless @cookie_store.empty? || (!accept_cookies? && @opts[:cookies].nil?)

        retries = 0
        begin
            start = Time.now()
            response = connection(url).get(full_path, opts)
            finish = Time.now()
            response_time = ((finish - start) * 1000).round
            @cookie_store.merge!(response['Set-Cookie']) if accept_cookies?
            return response, response_time
        rescue Exception => e
            retries += 1
            
            print_error( e.to_s )
            print_info( ( 7 - retries ).to_s +
                ' retries remaining for url: ' + url.to_s )
                
            print_debug_backtrace( e )
            refresh_connection(url)
            retry unless retries > 7
        end
    end

end
{'fraction_non_alphanumeric': 0.1085152167230249, 'fraction_numerical': 0.007992622194897018, 'mean_word_length': 2.081439393939394, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2053904', 'n_tokens_mistral': 1006, 'n_tokens_neox': 956, 'n_words': 266}