Skip to content

Commit 8b4e298

Browse files
committed
Lower open/read timeouts to 5 seconds for HEAD requests
1 parent 4075277 commit 8b4e298

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/link_checker.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class LinkChecker
2+
TIMEOUT = 5
23
attr_reader :log
34

45
def initialize(log: true)
@@ -43,7 +44,7 @@ def bad_response(url)
4344
sleep(n)
4445
end
4546
@prev_host = host
46-
code = HTTParty.head(url, verify: false).code
47+
code = HTTParty.head(url, verify: false, open_timeout: TIMEOUT, read_timeout: TIMEOUT).code
4748
code = get_code(url) if code == 400 || code == 405 # Try a GET if HEAD not allowed (or generic 400 error)
4849
return nil if code >= 200 && code < 400 # Success or redirects are OK
4950
return code
@@ -63,7 +64,7 @@ def bad_response(url)
6364
end
6465

6566
# Gets a response code using a GET request, for the case where HEAD is not supported.
66-
def get_code(url, redirect_limit: 5, open_timeout: 5, read_timeout: 5, use_range: true)
67+
def get_code(url, redirect_limit: 5, open_timeout: TIMEOUT, read_timeout: TIMEOUT, use_range: true)
6768
raise StandardError, 'too many redirects' if redirect_limit <= 0
6869

6970
uri = URI(url)

0 commit comments

Comments
 (0)