lib/wmap/utils/url_magic.rb
# Test the URL and return the response code
Test the URL and return the response code
Test the URL and return the response code
def response_code (url)
		puts "Check the http response code on the url: #{url}" if @verbose
		code = 10000	
		raise "Invalid url: #{url}" unless is_url?(url)
		url=url.strip.downcase
		timeo = Max_http_timeout/1000.0
		uri = URI.parse(url)
		http = Net::HTTP.new(uri.host, uri.port)
		http.open_timeout = timeo
		http.read_timeout = timeo
		if (url =~ /https\:/i)
			http.use_ssl = true
			http.verify_mode = OpenSSL::SSL::VERIFY_NONE
		end
		request = Net::HTTP::Get.new(uri.request_uri)
		response = http.request(request)
		puts "Server response the following: #{response}" if @verbose
		code = response.code.to_i
		@url_code=Hash.new unless @url_code
    @url_code[url]=code
		puts "Response code on #{url}: #{code}" if @verbose
		return code
	rescue Exception => ee
		puts "Exception on method #{__method__} for #{url}: #{ee}" if @verbose
		case ee
		when Errno::ECONNRESET
			code=104
		when Errno::ECONNABORTED,Errno::ETIMEDOUT
		when Timeout::Error				
			if (url =~ /https\:/i)		
				http.ssl_version = :SSLv3
				response = http.request(request)
				code = response.code.to_i
				unless code.nil?
					@ssl_version = http.ssl_version
				end
			end
		else
		end
    @url_code=Hash.new unless @url_code
		@url_code[url]=code
		return code
	end
def response_code ( url ) puts "Check the http response code on the url: #{url}" if @verbose code = 10000 raise "Invalid url: #{url}" unless is_url? ( url ) url = url . strip . downcase timeo = Max_http_timeout / 1000.0 uri = URI . parse ( url ) http = Net :: HTTP . new ( uri . host , uri . port ) http . open_timeout = timeo http . read_timeout = timeo if ( url =~ / https \: /i ) http . use_ssl = true http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE end request = Net :: HTTP :: Get . new ( uri . request_uri ) response = http . request ( request ) puts "Server response the following: #{response}" if @verbose code = response . code . to_i @url_code = Hash . new unless @url_code @url_code [ url ] = code puts "Response code on #{url}: #{code}" if @verbose return code rescue Exception => ee puts "Exception on method #{__method__} for #{url}: #{ee}" if @verbose case ee when Errno :: ECONNRESET code = 104 when Errno :: ECONNABORTED , Errno :: ETIMEDOUT when Timeout :: Error if ( url =~ / https \: /i ) http . ssl_version = :SSLv3 response = http . request ( request ) code = response . code . to_i unless code . nil? @ssl_version = http . ssl_version end end else end @url_code = Hash . new unless @url_code @url_code [ url ] = code return code end
Test the URL and return the response code
Test the URL and return the response code
# All unknown url connection exceptions go here #http.ssl_version = :SSLv3 # Bypass the remote web server cert validation test #response.finish if response.started?() # rescue "Connection reset by peer" error type #code=10000 # Quick fix # try again for ssl timeout session, in case of default :TLSv1 failure #code=10000
url
<not_specific>