Class: Proxy::BrightData
Instance Method Summary collapse
Methods inherited from Base
#format_response, #get_headers, #initialize, #prepare_request, #success_response?, #with_retry
Constructor Details
This class inherits a constructor from Proxy::Base
Instance Method Details
#fetch(url, proxy_from_server) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/proxy/bright_data.rb', line 7 def fetch(url, proxy_from_server) uri = URI.parse(url) proxy_uri = URI.parse(proxy_from_server['proxyUrl']) http = prepare_request(uri, proxy_uri) uri.query = URI.encode_www_form(@query_params) unless @query_params.empty? request = Net::HTTP::Get.new(uri, @headers) .each do || request.add_field('Cookie', "#{cookie[:name]}=#{cookie[:value]}") end response = with_retry do http.request(request) end format_response(response) rescue StandardError => e @logger.error("Request failed error: #{e.message}") nil end |