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, response = nil) ⇒ Target



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

def initialize(url, response = nil)
  @url = url.to_s
  @response = response || open_url
  build
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#raw_headersObject (readonly)

Returns the value of attribute raw_headers.



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

def raw_headers
  @raw_headers
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



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

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.



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

def status
  @status
end

#uriObject (readonly)

Returns the value of attribute uri.



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

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.meta_refresh_regexObject



47
48
49
# File 'lib/whatweb/target.rb', line 47

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

Instance Method Details

#buildObject



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

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



35
36
37
# File 'lib/whatweb/target.rb', line 35

def md5sum
  @md5sum ||= response.md5sum
end

#open_urlObject



16
17
18
# File 'lib/whatweb/target.rb', line 16

def open_url
  HTTP.get url
end


30
31
32
33
# File 'lib/whatweb/target.rb', line 30

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

#tag_patternObject



39
40
41
# File 'lib/whatweb/target.rb', line 39

def tag_pattern
  @tag_pattern ||= response.tag_pattern
end

#textObject



43
44
45
# File 'lib/whatweb/target.rb', line 43

def text
  @text ||= response.text
end