url_monitor/url_monitor.rb
# returns the http response from a url
# CONFUSING: note that the response is a String when an error occurs.
returns the http response from a url
CONFUSING: note that the response is a String when an error occurs.
returns the http response from a url CONFUSING : note that the response is a String when an error occurs .
def http_response(url)
    uri = URI.parse(url)
    response = nil
    retry_url_execution_expired = true
    begin
      connect_host = option('host_override').to_s.strip
      connect_host = uri.host if connect_host.empty?
      http = Net::HTTP.new(connect_host,uri.port)
      http.use_ssl = url =~ %r{\Ahttps://}
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
      http.open_timeout = option('timeout_length').to_i
      http.start(){|h|
            req = Net::HTTP::Head.new((uri.path != '' ? uri.path : '/' ) + (uri.query ? ('?' + uri.query) : ''))
            req['User-Agent'] = "ScoutURLMonitor/#{Scout::VERSION}"
            req['host'] = uri.host
            if uri.user && uri.password
              req.basic_auth uri.user, uri.password
            end
            response = h.request(req)
      }
    rescue Exception => e
      if e.message =~ /execution expired/ and retry_url_execution_expired
        retry_url_execution_expired = false
        retry
      else
        response = e.to_s
      end
    end
    return response
  end
def http_response ( url ) uri = URI . parse ( url ) response = nil retry_url_execution_expired = true begin connect_host = option ( 'host_override' ) . to_s . strip connect_host = uri . host if connect_host . empty? http = Net :: HTTP . new ( connect_host , uri . port ) http . use_ssl = url =~ %r{ \A https:// } http . verify_mode = OpenSSL :: SSL :: VERIFY_NONE http . open_timeout = option ( 'timeout_length' ) . to_i http . start ( ) { | h | req = Net :: HTTP :: Head . new ( ( uri . path != '' ? uri . path : '/' ) + ( uri . query ? ( '?' + uri . query ) : '' ) ) req [ 'User-Agent' ] = "ScoutURLMonitor/#{Scout::VERSION}" req [ 'host' ] = uri . host if uri . user && uri . password req . basic_auth uri . user , uri . password end response = h . request ( req ) } rescue Exception => e if e . message =~ / execution expired / and retry_url_execution_expired retry_url_execution_expired = false retry else response = e . to_s end end return response end
returns the http response from a url
CONFUSING: note that the response is a String when an error occurs.
returns the http response from a url CONFUSING : note that the response is a String when an error occurs .
url
<not_specific>