Class: HttpClient
- Inherits:
-
Object
- Object
- HttpClient
- 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
- #get(urls, options = {}) ⇒ Object
-
#initialize ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(urls, body, options = {}) ⇒ Object
- #request_options(method, options, body = nil) ⇒ Object
Constructor Details
#initialize ⇒ HttpClient
Returns a new instance of HttpClient.
9 10 11 12 |
# File 'lib/fingerprinter/core/http_client.rb', line 9 def initialize Typhoeus::Config.user_agent = ScanOptions.user_agent @hydra = Typhoeus::Hydra.new(max_concurrency: ScanOptions.http_concurrency) end |
Instance Method Details
#get(urls, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fingerprinter/core/http_client.rb', line 38 def get(urls, = {}) responses = {} urls = [urls] if urls.is_a?(String) urls.each do |url| http_request = Typhoeus::Request.new(url, (:get, )) http_request.on_complete { |response| responses[url] = response } @hydra.queue(http_request) end @hydra.run responses end |
#post(urls, body, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fingerprinter/core/http_client.rb', line 55 def post(urls, body, = {}) responses = {} urls = [urls] if urls.is_a?(String) urls.each do |url| http_request = Typhoeus::Request.new(url, (:post, , body)) http_request.on_complete { |response| responses[url] = response } @hydra.queue(http_request) end @hydra.run responses end |
#request_options(method, options, body = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fingerprinter/core/http_client.rb', line 14 def (method, , body = nil) = { ssl_verifypeer: false, ssl_verifyhost: 0, followlocation: [:follow_location] || false, method: method, headers: [:headers] || {}, body: body } [: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' }) [:params] = [:params] if [:params] [:proxy] = ScanOptions.proxy_url if ScanOptions.proxy? [:timeout] = ScanOptions.timeout end |