fingerprinter 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fingerprinter.rb +33 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e23aed5ef3ed13d6d87ce5c9a60f8ae7c76b1af3072e5743e2d2fe97613c69a0
4
- data.tar.gz: 5fdd5658a3eef4660f3c7274065e409b47e602c4a3f213c90de0bc002f052688
3
+ metadata.gz: 5a235ab2c1e2f911a87dd87eaa83d1b81ae974614f57ded0e9c69dd96c946b4d
4
+ data.tar.gz: f0b6197d8604b4b655a53cd2d7112f2f142e5048135956137518cd1011b1dcc9
5
5
  SHA512:
6
- metadata.gz: 80134337a1020a483c849b4e54944531cf414a47325e8b51365f95bfebaaac8beab2b9b8e963f76a05a6cc218b57fb7c45756cfdf54bf6bba616919e7f2bab46
7
- data.tar.gz: a4d1599414026b37d11628e6c84abba00c071c05857ee4ca9b833149fe3f8a81a384f6d4b0fe10f36833b8bbd0d0dfd7afd21566ca177476c71865dd5a38902b
6
+ metadata.gz: 4720f0b52bf5130c980d759abc42ae829dd64da3feedb3c65c67be159d55500700433ea6d27483a1ff65dd8caa7e3e4b467ca46de7f173c68969df5d2f633815
7
+ data.tar.gz: f9a778664a1e258ee7894daf4eb9dee52bd40b3e925b5fa6c890df8126c151fc36f979ea97486d1979f9eafdd4a0f285fa42b2029b0a6147abe840ec3b477051
data/lib/fingerprinter.rb CHANGED
@@ -35,7 +35,7 @@ module Fingerprinter
35
35
  response = get_response(url)
36
36
  next unless response
37
37
 
38
- url = Utilities::Urls.up_to_port(response.effective_url)
38
+ url = effective_url(response, url)
39
39
 
40
40
  responses = response.redirections
41
41
  responses << response
@@ -59,20 +59,47 @@ module Fingerprinter
59
59
  response = nil
60
60
  3.times do
61
61
  response = Fingerprinter.http_client.get(url, { follow_location: true })[url]
62
- break if response&.code != 0 && !response.return_message.include?('Stream error')
62
+ break if response&.code != 0 || timeout_without_scheme?(url, response)
63
63
 
64
64
  sleep(1)
65
65
  end
66
- return if response&.code&.zero?
67
- return response if same_scope?(url, response)
66
+
67
+ if stream_error?(response)
68
+ return
69
+ elsif timeout_without_scheme?(url, response)
70
+ url = normalize_url(url)
71
+ return get_response(url)
72
+ end
73
+ return if response&.code == 0
74
+ return response if response.redirections.empty? || same_scope?(url, response)
68
75
 
69
76
  response.redirections.first
70
77
  end
71
78
 
79
+ def effective_url(response, url)
80
+ effective_url = Utilities::Urls.up_to_port(response.effective_url)
81
+ effective_url.nil? ? normalize_url(url) : effective_url
82
+ end
83
+
84
+ def normalize_url(url)
85
+ url.start_with?('http') ? url : "https://#{url}"
86
+ end
87
+
72
88
  def same_scope?(url, response)
73
- url = "https://#{url}" unless url.start_with?('http')
89
+ url = normalize_url(url)
90
+
91
+ base_host = Utilities::Urls.uri_parse(url)&.host
92
+ response_host = Utilities::Urls.uri_parse(response&.effective_url)&.host
93
+
94
+ base_host == response_host || 'www.' + base_host == response_host
95
+ end
96
+
97
+ def stream_error?(response)
98
+ response&.code&.zero? && response.return_message.include?('Stream error')
99
+ end
74
100
 
75
- Utilities::Urls.uri_parse(url)&.host == Utilities::Urls.uri_parse(response&.effective_url)&.host
101
+ def timeout_without_scheme?(url, response)
102
+ response&.code == 0 && !url.start_with?('http') && response.return_message.include?('Timeout was reached')
76
103
  end
77
104
  end
78
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fingerprinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua MARTINELLE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-10 00:00:00.000000000 Z
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby