Changed way to maek get requests to allow timeouts. Also made any error during fetching (I did this because there are WAY to many web related errors when testing.)

This commit is contained in:
2026-07-15 23:59:23 -06:00
parent 965b3b50b7
commit e1753ab2ce
2 changed files with 38 additions and 22 deletions
+36 -21
View File
@@ -2,6 +2,26 @@ require "option_parser"
require "http/client"
require "validator"
OptionParser.parse do |parser|
parser.banner = "Usage: rete [arguments] [urls]"
parser.on("-f FILE", "--file=FILE", "Checks all urls in a txt file.") { |file|
urls = File.read(file)
checkUrlFromFile urls
exit 0}
parser.on("-v", "--version", "Displays current version of rete.") {
puts "Rete 1.0 by koffee.zip"
exit(0)}
parser.on("-h", "--help", "Show this help") do
puts parser
exit
end
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end
def checkUrlFromFile(content) # Sorry for the crappy method name.
repeat = 0
working = 0
@@ -12,9 +32,22 @@ def checkUrlFromFile(content) # Sorry for the crappy method name.
urls = content.split("\n")
while repeat < urls.size
if Valid.url? urls[repeat]
begin
validUrl = Valid.url? urls[repeat]
rescue Regex::Error
validUrl = false
end
if validUrl == true
begin
response = HTTP::Client.get(urls[repeat])
STDIN.read_timeout = 1
uri = URI.parse(urls[repeat])
client = HTTP::Client.new(uri)
client.connect_timeout = 5.seconds
client.read_timeout = 10.seconds
client.write_timeout = 5.seconds
response = client.get("/")
if config.includes?(response.status_code.to_s)
puts "#{urls[repeat]} is a valid URL and works. Status code: #{response.status_code}"
working += 1
@@ -22,7 +55,7 @@ def checkUrlFromFile(content) # Sorry for the crappy method name.
puts "#{urls[repeat]} is a valid URL but does not work. Status Code: #{response.status_code}"
notWorking += 1
end
rescue Socket::Addrinfo::Error
rescue
puts "#{urls[repeat]} is a valid URL but does not exist."
notWorking += 1
end
@@ -41,24 +74,6 @@ def checkUrlFromFile(content) # Sorry for the crappy method name.
exit 0
end
OptionParser.parse do |parser|
parser.banner = "Usage: rete [arguments] [urls]"
parser.on("-f FILE", "--file=FILE", "Checks all urls in a txt file.") { |file|
urls = File.read(file)
checkUrlFromFile urls
exit 0}
parser.on("-v", "--version", "Displays current version of rete.") {puts "Rete 1.0 by koffee.zip"}
parser.on("-h", "--help", "Show this help") do
puts parser
exit
end
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end
repeat = 0
working = 0
notWorking = 0