fingerprinter 0.1.5 → 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 +17 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f6821303bf8854c4b159cc1038bfb08af71d170b07a24e19376f49f88bba6ee
4
- data.tar.gz: edd7faad955013acf5c94e897e4994e340baafc493c3f2c1bfccdb2bf7558f7c
3
+ metadata.gz: 5a235ab2c1e2f911a87dd87eaa83d1b81ae974614f57ded0e9c69dd96c946b4d
4
+ data.tar.gz: f0b6197d8604b4b655a53cd2d7112f2f142e5048135956137518cd1011b1dcc9
5
5
  SHA512:
6
- metadata.gz: 711d27cdd3329f07e6e24daa9400e36a8e8f62c6467870c0dc0309ed75bd1aa9713aaede490b9c882e91e1e69d8b9ccb0c20077f6e42a00353b03db685483078
7
- data.tar.gz: 49b065930036587200a211e12337e67bd6a61643e0101c9e2ddb860bc5454542ce74fb33557a4ac830dfa27159410ea2317eee8f751ed49848265a8bc4834bb0
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
@@ -67,19 +67,31 @@ module Fingerprinter
67
67
  if stream_error?(response)
68
68
  return
69
69
  elsif timeout_without_scheme?(url, response)
70
- url = "https://#{url}"
70
+ url = normalize_url(url)
71
71
  return get_response(url)
72
72
  end
73
73
  return if response&.code == 0
74
- return response if same_scope?(url, response)
74
+ return response if response.redirections.empty? || same_scope?(url, response)
75
75
 
76
76
  response.redirections.first
77
77
  end
78
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
+
79
88
  def same_scope?(url, response)
80
- 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
81
93
 
82
- Utilities::Urls.uri_parse(url)&.host == Utilities::Urls.uri_parse(response&.effective_url)&.host
94
+ base_host == response_host || 'www.' + base_host == response_host
83
95
  end
84
96
 
85
97
  def stream_error?(response)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fingerprinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua MARTINELLE