lib/vidibus/validate_uri/core.rb
# Checks if given uri is accessible.
# The check will not be performed in test environment.
#
Checks if given uri is accessible.
The check will not be performed in test environment.
Checks if given uri is accessible . The check will not be performed in test environment .
def accessible_uri?(uri)
        return false unless valid_uri?(uri)
        _uri = URI.parse(uri)
        path = _uri.path.blank? ? '/' : _uri.path
        begin
          http = Net::HTTP.new(_uri.host, _uri.port)
          if _uri.scheme == 'https'
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
          end
          http.start do |http|
            code = http.head(path).code
            return (code and code.to_i < 400)
          end
        rescue SocketError => e
          if defined?(Rails) && Rails.logger
            Rails.logger.error "Accessing #{_uri.host} on port #{_uri.port} failed: #{e.inspect}"
          end
          false
        end
      end
def accessible_uri? ( uri ) return false unless valid_uri? ( uri ) _uri = URI . parse ( uri ) path = _uri . path . blank? ? '/' : _uri . path begin http = Net :: HTTP . new ( _uri . host , _uri . port ) if _uri . scheme == 'https' http . use_ssl = true http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE end http . start do | http | code = http . head ( path ) . code return ( code and code . to_i < 400 ) end rescue SocketError => e if defined? ( Rails ) && Rails . logger Rails . logger . error "Accessing #{_uri.host} on port #{_uri.port} failed: #{e.inspect}" end false end end
Checks if given uri is accessible.
Checks if given uri is accessible .
uri
<not_specific>