Sha256: 70df199e645f7ed08cfa1a9745e993cdd2cdb61b0b30e68ea0b30014f9163aca
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true # Released under the MIT License. # Copyright, 2018-2022, by Samuel Williams. require_relative '../spider' require 'async/await' require 'samovar' require 'uri' require 'console' module Benchmark module HTTP module Command class Spider < Samovar::Command include Async::Await self.description = "Spider a website and report on performance." options do option '-d/--depth <count>', "The number of nested URLs to traverse.", default: 10, type: Integer option '-h/--headers', "Print out the response headers", default: false end many :urls, "One or more hosts to benchmark" def log(method, url, response) Console.logger.public_send(response.failure? ? :warn : :info, self) do |buffer| buffer.puts "#{method} #{url} -> #{response.version} #{response.status} (#{response.body&.length || 'unspecified'} bytes)" response.headers.each do |key, value| buffer.puts "\t#{key}: #{value}" end if @options[:headers] end end sync def call spider = HTTP::Spider.new(depth: @options[:depth]) statistics = spider.call(@urls, &self.method(:log)) Console.logger.info(self, statistics: statistics) return statistics end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
benchmark-http-0.16.1 | lib/benchmark/http/command/spider.rb |
benchmark-http-0.16.0 | lib/benchmark/http/command/spider.rb |