Check body size : HTML Parser « Network « Ruby






Check body size


require 'net/http'
require 'uri'

module Net
  class HTTP
    def HTTP.get_with_headers(uri, headers=nil)
      uri = URI.parse(uri) if uri.respond_to? :to_str
      start(uri.host, uri.port) do |http|
        path_query = uri.path + (uri.query ? ('?' + uri.query) : '')
        return http.get(path_query, headers)
      end
    end
  end
end

uncompressed = Net::HTTP.get_with_headers('http://www.cnn.com/')
uncompressed.body.size

 








Related examples in the same category

1.Extract URL
2.Customizing HTTP Request Headers
3.Grab links for anchor and image