Class: WhatWeb::Target

Inherits:
Object show all
Defined in:
lib/whatweb/target.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, opts = {}) ⇒ Target

Returns a new instance of Target.



11
12
13
14
15
16
# File 'lib/whatweb/target.rb', line 11

def initialize(url, opts = {})
  @url = url.to_s
  @user_agent = opts[:user_agent] || "WhatWeb/#{VERSION}"
  @response = opts[:response] || open_url
  build
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def headers
  @headers
end

#raw_headersObject (readonly)

Returns the value of attribute raw_headers.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def raw_headers
  @raw_headers
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def raw_response
  @raw_response
end

#responseObject

Returns the value of attribute response.



7
8
9
# File 'lib/whatweb/target.rb', line 7

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def status
  @status
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/whatweb/target.rb', line 9

def url
  @url
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



8
9
10
# File 'lib/whatweb/target.rb', line 8

def user_agent
  @user_agent
end

Class Method Details

.meta_refresh_regexObject



49
50
51
# File 'lib/whatweb/target.rb', line 49

def self.meta_refresh_regex
  /<meta[\s]+http\-equiv[\s]*=[\s]*['"]?refresh['"]?[^>]+content[\s]*=[^>]*[0-9]+;[\s]*url=['"]?([^"'>]+)['"]?[^>]*>/i
end

Instance Method Details

#buildObject



22
23
24
25
26
27
28
29
30
# File 'lib/whatweb/target.rb', line 22

def build
  @body = response.body.to_s
  @headers = response.headers.to_a.map { |k, v| [k.downcase, v] }.to_h
  @headers["set-cookie"] = set_cookie if response.headers["Set-Cookie"]
  @raw_headers = response.headers.to_a.map { |h| h.join(":") }.join("\n")
  @raw_response = body + raw_headers
  @status = response.status
  @uri = response.uri
end

#md5sumObject



37
38
39
# File 'lib/whatweb/target.rb', line 37

def md5sum
  @md5sum ||= response.md5sum
end

#open_urlObject



18
19
20
# File 'lib/whatweb/target.rb', line 18

def open_url
  HTTP.headers(user_agent: user_agent).get url
end


32
33
34
35
# File 'lib/whatweb/target.rb', line 32

def set_cookie
  cookie = response.headers["Set-Cookie"]
  cookie.is_a?(String) ? cookie : cookie.join("\n")
end

#tag_patternObject



41
42
43
# File 'lib/whatweb/target.rb', line 41

def tag_pattern
  @tag_pattern ||= response.tag_pattern
end

#textObject



45
46
47
# File 'lib/whatweb/target.rb', line 45

def text
  @text ||= response.text
end