title: Check if webpage is online, with Ruby
body: <p>With <code>curl</code>, I do the following to check if a webpage is online:</p>
  
  <pre><code>if curl --output /dev/null --silent --head --fail "${url}"; then
    echo "URL exists: ${url}"
  else
    echo "URL does not exist: ${url}"
  fi
  </code></pre>
  
  <p>However, if the server refuses <code>HEAD</code> requests (or I don’t know), an alternative is to request only the first byte of the file:</p>
  
  <pre><code>if curl --output /dev/null --silent --fail --range 0-0 "${url}"; then
    echo "URL exists: ${url}"
  else
    echo "URL does not exist: ${url}"
  fi
  </code></pre>
  
  <p>The first case is easy to replicate in Ruby:</p>
  
  <pre><code>require 'net/http'
  require 'uri'
  
  uri = URI.parse(url)
  response = Net::HTTP.get_response(uri)
  
  if response.kind_of? Net::HTTPOK
    puts "URL exists: #{url}"
  else
    puts "URL does not exist: #{url}"
  end
  </code></pre>
  
  <p>How do I replicate the second <code>curl</code> case?</p>