lib/benchmark/http/spider.rb in benchmark-http-0.16.1 vs lib/benchmark/http/spider.rb in benchmark-http-0.18.0

- old
+ new

@@ -1,21 +1,21 @@ # frozen_string_literal: true # Released under the MIT License. -# Copyright, 2020-2022, by Samuel Williams. +# Copyright, 2020-2024, by Samuel Williams. -require_relative 'seconds' -require_relative 'statistics' -require_relative 'links_filter' +require_relative "seconds" +require_relative "statistics" +require_relative "links_filter" -require 'async' -require 'async/http/client' -require 'async/http/endpoint' -require 'async/await' +require "async" +require "async/http/client" +require "async/http/endpoint" +require "async/await" -require 'uri' -require 'console' +require "uri" +require "console" module Benchmark module HTTP class Spider include Async::Await @@ -74,23 +74,23 @@ response = client.head(request_uri).tap(&:read) yield("HEAD", url, response) if block_given? if response.redirection? - location = url + response.headers['location'] + location = url + response.headers["location"] if location.host == url.host Console.logger.debug(self) {"Following redirect to #{location}..."} fetch(statistics, client, location, depth&.-(1), fetched, &block).wait return else Console.logger.debug(self) {"Ignoring redirect to #{location}."} return end end - content_type = response.headers['content-type'] - unless content_type&.start_with? 'text/html' + content_type = response.headers["content-type"] + unless content_type&.start_with? "text/html" # puts "Unsupported content type: #{content_type}" return end response = statistics.measure do @@ -112,10 +112,10 @@ statistics = Statistics.new urls.each do |url| endpoint = Async::HTTP::Endpoint.parse(url, timeout: 10) - Async::HTTP::Client.open(endpoint, protocol: endpoint.protocol, connection_limit: 4) do |client| + Async::HTTP::Client.open(endpoint, protocol: endpoint.protocol, limit: 4) do |client| fetch(statistics, client, endpoint.url, &block).wait end end return statistics