ruby-link-checker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/coverage/index.html +1062 -743
- data/lib/ruby-link-checker/net/http/checker.rb +0 -1
- data/lib/ruby-link-checker/tasks.rb +13 -2
- data/lib/ruby-link-checker/typhoeus/hydra/checker.rb +0 -2
- data/lib/ruby-link-checker/version.rb +1 -1
- data/pkg/ruby-link-checker-0.1.0.gem +0 -0
- data/spec/fixtures/308_429.yml +108 -0
- data/spec/support/link_checker.rb +13 -0
- metadata +3 -2
@@ -9,7 +9,6 @@ module LinkChecker
|
|
9
9
|
request = ::Net::HTTPGenericRequest.new(method, false, true, uri)
|
10
10
|
request['User-Agent'] = checker.user_agent
|
11
11
|
response = http.request(request)
|
12
|
-
logger.debug "#{method} #{uri}: #{response.code}"
|
13
12
|
result! Result.new(uri, method, original_uri, request, response, options)
|
14
13
|
end
|
15
14
|
end
|
@@ -28,7 +28,6 @@ module LinkChecker
|
|
28
28
|
_queue_task(uri, method, original_uri || uri, options)
|
29
29
|
elsif methods_left.any?
|
30
30
|
@method = methods_left.shift
|
31
|
-
@redirects = [uri]
|
32
31
|
@uri = URI(@uri) unless @uri.is_a?(URI)
|
33
32
|
_queue_task(uri, method, original_uri || uri, options)
|
34
33
|
elsif @result && result.error?
|
@@ -72,9 +71,20 @@ module LinkChecker
|
|
72
71
|
_handle_result ResultError.new(uri, method, original_uri, e, options)
|
73
72
|
end
|
74
73
|
|
74
|
+
def _retries_left_s
|
75
|
+
return nil unless retry? && retries_left > 0
|
76
|
+
|
77
|
+
if retries_left == 1
|
78
|
+
'1 retry left'
|
79
|
+
else
|
80
|
+
"#{retries_left} retries left"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
75
84
|
def _handle_result(result)
|
76
85
|
@result = result
|
77
|
-
|
86
|
+
retry_text = " (#{_retries_left_s})" if retry? && (result.error? || result.failure?)
|
87
|
+
logger.info "#{' ' * (redirects.count - 1)}#{result}#{retry_text}"
|
78
88
|
result! result
|
79
89
|
if result.redirect?
|
80
90
|
redirect! result
|
@@ -89,6 +99,7 @@ module LinkChecker
|
|
89
99
|
elsif result.success?
|
90
100
|
success! result
|
91
101
|
else
|
102
|
+
@redirects = [uri]
|
92
103
|
execute!
|
93
104
|
end
|
94
105
|
rescue StandardError => e
|
@@ -16,10 +16,8 @@ module LinkChecker
|
|
16
16
|
)
|
17
17
|
request.on_complete do |response|
|
18
18
|
if response.timed_out?
|
19
|
-
logger.debug "#{method} #{uri}: #{response.return_code}"
|
20
19
|
result! ResultError.new(uri, method, original_uri, Timeout::Error.new, options)
|
21
20
|
else
|
22
|
-
logger.debug "#{method} #{uri}: #{response.code}"
|
23
21
|
result! Result.new(uri, method, original_uri, request, response, options)
|
24
22
|
end
|
25
23
|
end
|
Binary file
|
@@ -0,0 +1,108 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: head
|
5
|
+
uri: https://www.example.org/
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Ruby Link Checker/0.2.0
|
12
|
+
Expect:
|
13
|
+
- ''
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 308
|
17
|
+
message: ''
|
18
|
+
headers:
|
19
|
+
server:
|
20
|
+
- CloudFront
|
21
|
+
date:
|
22
|
+
- Mon, 03 Apr 2023 00:01:15 GMT
|
23
|
+
content-length:
|
24
|
+
- '0'
|
25
|
+
location:
|
26
|
+
- https://www.dblock.org/
|
27
|
+
x-cache:
|
28
|
+
- FunctionGeneratedResponse from cloudfront
|
29
|
+
via:
|
30
|
+
- 1.1 49830f6fdfb2c3519e81248d6d19f450.cloudfront.net (CloudFront)
|
31
|
+
x-amz-cf-pop:
|
32
|
+
- EWR52-C4
|
33
|
+
x-amz-cf-id:
|
34
|
+
- BRpz7eXeEToGF8Ytac3rGh6DHQZLwnZBdNOxnDICSUPoHDN6wHDxWQ==
|
35
|
+
body:
|
36
|
+
encoding: UTF-8
|
37
|
+
string: ''
|
38
|
+
http_version: '2'
|
39
|
+
adapter_metadata:
|
40
|
+
effective_url: https://www.example.org/
|
41
|
+
recorded_at: Mon, 03 Apr 2023 00:01:15 GMT
|
42
|
+
- request:
|
43
|
+
method: head
|
44
|
+
uri: https://www.dblock.org/
|
45
|
+
body:
|
46
|
+
encoding: US-ASCII
|
47
|
+
string: ''
|
48
|
+
headers:
|
49
|
+
User-Agent:
|
50
|
+
- Ruby Link Checker/0.2.0
|
51
|
+
Expect:
|
52
|
+
- ''
|
53
|
+
response:
|
54
|
+
status:
|
55
|
+
code: 429
|
56
|
+
message: ''
|
57
|
+
headers:
|
58
|
+
server:
|
59
|
+
- nginx
|
60
|
+
date:
|
61
|
+
- Mon, 03 Apr 2023 00:01:15 GMT
|
62
|
+
content-type:
|
63
|
+
- text/html; charset=utf-8
|
64
|
+
vary:
|
65
|
+
- Accept-Encoding
|
66
|
+
- Accept
|
67
|
+
x-frame-options:
|
68
|
+
- SAMEORIGIN
|
69
|
+
x-xss-protection:
|
70
|
+
- '0'
|
71
|
+
x-content-type-options:
|
72
|
+
- nosniff
|
73
|
+
x-download-options:
|
74
|
+
- noopen
|
75
|
+
x-permitted-cross-domain-policies:
|
76
|
+
- none
|
77
|
+
referrer-policy:
|
78
|
+
- strict-origin-when-cross-origin
|
79
|
+
x-discourse-route:
|
80
|
+
- users/show
|
81
|
+
cache-control:
|
82
|
+
- no-cache, no-store
|
83
|
+
content-security-policy:
|
84
|
+
- upgrade-insecure-requests; base-uri 'self'; object-src 'none'; script-src
|
85
|
+
https://forum.opensearch.org/logs/ https://forum.opensearch.org/sidekiq/ https://forum.opensearch.org/mini-profiler-resources/
|
86
|
+
https://global.discourse-cdn.com/business5/assets/ https://global.discourse-cdn.com/business5/brotli_asset/
|
87
|
+
https://forum.opensearch.org/extra-locales/ https://sea1.discourse-cdn.com/business5/highlight-js/
|
88
|
+
https://sea1.discourse-cdn.com/business5/javascripts/ https://sea1.discourse-cdn.com/business5/plugins/
|
89
|
+
https://sea1.discourse-cdn.com/business5/theme-javascripts/ https://sea1.discourse-cdn.com/business5/svg-sprite/
|
90
|
+
'sha256-Gty3/aPWFfSvz7pdT39HY97/+2opLup9V0L19ZF0IwY=' https://forum.opensearch.org/plugins/discourse-client-performance/javascripts/discourse-client-performance.js;
|
91
|
+
worker-src 'self' https://global.discourse-cdn.com/business5/assets/ https://global.discourse-cdn.com/business5/brotli_asset/
|
92
|
+
https://sea1.discourse-cdn.com/business5/javascripts/ https://sea1.discourse-cdn.com/business5/plugins/;
|
93
|
+
frame-ancestors 'self'; manifest-src 'self'
|
94
|
+
x-request-id:
|
95
|
+
- a54de95c-ab20-4f9a-81a0-93908fc94357
|
96
|
+
cdck-proxy-id:
|
97
|
+
- app-router-tiehunter03.sea1
|
98
|
+
- app-balancer-tieinterceptor1b.sea1
|
99
|
+
strict-transport-security:
|
100
|
+
- max-age=31536000
|
101
|
+
body:
|
102
|
+
encoding: UTF-8
|
103
|
+
string: ''
|
104
|
+
http_version: '2'
|
105
|
+
adapter_metadata:
|
106
|
+
effective_url: https://www.dblock.org/
|
107
|
+
recorded_at: Mon, 03 Apr 2023 00:01:15 GMT
|
108
|
+
recorded_with: VCR 6.1.0
|
@@ -240,6 +240,19 @@ shared_context 'a link checker' do
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
+
context 'a failed retry on a redirect', vcr: { cassette_name: '308+429', allow_playback_repeats: true } do
|
244
|
+
subject do
|
245
|
+
described_class.new(methods: %w[HEAD], retries: 2)
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'calls redirect callback' do
|
249
|
+
expect(result.success?).to be false
|
250
|
+
expect(result.failure?).to be true
|
251
|
+
expect(result.error?).to be false
|
252
|
+
expect(result.error).not_to be_a LinkChecker::Errors::RedirectLoopError
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
243
256
|
context 'an invalid URI' do
|
244
257
|
let(:url) { '\/invalid-url' }
|
245
258
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-link-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- spec/fixtures/301_301.yml
|
101
101
|
- spec/fixtures/301_400_301_200.yml
|
102
102
|
- spec/fixtures/301_403.yml
|
103
|
+
- spec/fixtures/308_429.yml
|
103
104
|
- spec/fixtures/404.yml
|
104
105
|
- spec/fixtures/404_200.yml
|
105
106
|
- spec/fixtures/404_404.yml
|