http_status_checker 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 884c48b9bc2833265b0f97dac47f77017ea45a52
|
4
|
+
data.tar.gz: ef49ec1bf965d4b44749ac6011080405eb2ae197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be1ef7e4b381ac1191e6f44a99be459120fe05b79475e1fdefcc0cb075b73d1a06efde356e5d71a14a3fc6c3cd4e0e6544fdeab011adc88a241338a83baa49ab
|
7
|
+
data.tar.gz: 4a050c9820dc02996038373e516b671ec072f6c742392b9e7d5fdf7fb237e70e9df9b3eb19b9b820a06d1ed52c63af77720d4b468498fb0f19d743e9d3ec7c53
|
@@ -22,6 +22,13 @@ module HttpStatusChecker
|
|
22
22
|
|
23
23
|
def get_response(url, redirect_url = nil, redirect_count = 0, retry_count = 0)
|
24
24
|
result = HttpStatusChecker::Connection.get_header(redirect_url || url)
|
25
|
+
parse_response(redirect_count, redirect_url, result, url)
|
26
|
+
rescue => e
|
27
|
+
get_response(url, nil, redirect_count + 1, retry_count + 1) if retry_count < RETRY_MAX
|
28
|
+
{ url => { code: result ? result.code : nil, is_alive: false, error: e.message } }
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_response(redirect_count, redirect_url, result, url)
|
25
32
|
location_url = result['location']
|
26
33
|
if !location_url.nil? && (redirect_url || url) != location_url
|
27
34
|
raise InvalidRedirectError if redirect_count > REDIRECT_MAX
|
@@ -31,13 +38,6 @@ module HttpStatusChecker
|
|
31
38
|
else
|
32
39
|
raise InvalidResponseError, "Unknown class #{result.class} : #{result.to_s}"
|
33
40
|
end
|
34
|
-
rescue => e
|
35
|
-
if retry_count < RETRY_MAX
|
36
|
-
retry_count += 1
|
37
|
-
retry
|
38
|
-
end
|
39
|
-
code = result ? result.code : nil
|
40
|
-
{ url => { code: code, is_alive: false, error: e.message } }
|
41
41
|
end
|
42
42
|
|
43
43
|
def to_host_hash(urls)
|
@@ -78,6 +78,7 @@ describe HttpStatusChecker::Connection do
|
|
78
78
|
let!(:morizyun_404) { 'http://morizyun.github.io/404/' }
|
79
79
|
it 'returns is_alive = false, redirect = nil, error present' do
|
80
80
|
response = HttpStatusChecker.check(morizyun_404)
|
81
|
+
expect(response.first[morizyun_404][:code]).to eq('404')
|
81
82
|
expect(response.first[morizyun_404][:is_alive]).to eq(false)
|
82
83
|
expect(response.first[morizyun_404][:redirect_url]).to be_nil
|
83
84
|
expect(response.first[morizyun_404][:error]).not_to be_nil
|