Class: HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/fingerprinter/core/http_client.rb

Overview

HTTP Client used to perform some requests (check for some content for example) or as a fallback in some browser processing (less resource intensive than using a Chrome instance but won’t provide access to the DOM for example)

Instance Method Summary collapse

Constructor Details

#initializeHttpClient

Returns a new instance of HttpClient.



9
10
11
# File 'lib/fingerprinter/core/http_client.rb', line 9

def initialize
  Typhoeus::Config.user_agent = ScanOptions.user_agent
end

Instance Method Details

#get(url, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/fingerprinter/core/http_client.rb', line 37

def get(url, options = {})
  responses = {}

  http_request = Typhoeus::Request.new(url, request_options(:get, options))
  http_request.on_complete { |response| responses[url] = response }
  http_request.run

  responses
end

#request_options(method, options, body = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fingerprinter/core/http_client.rb', line 13

def request_options(method, options, body = nil)
  req_options = {
    ssl_verifypeer: false,
    ssl_verifyhost: 0,
    followlocation: options[:follow_location] || false,
    method: method,
    headers: options[:headers] || {},
    body: body
  }

  req_options[:headers].merge!({
                                 'Priority' => 'u=0, i',
                                 'Accept-Encoding' => 'gzip, deflate, br',
                                 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8'
                               })

  req_options[:params] = options[:params] if options[:params]

  req_options[:proxy] = ScanOptions.proxy_url if ScanOptions.proxy?
  req_options[:timeout] = ScanOptions.timeout

  req_options
end