diff --git a/app/models/concerns/request_helper.rb b/app/models/concerns/request_helper.rb index 45893bfb..52f3516e 100644 --- a/app/models/concerns/request_helper.rb +++ b/app/models/concerns/request_helper.rb @@ -139,9 +139,7 @@ def request_url(url, verb = 'Get') end def request_uri(uri, verb = 'Get') - http = Net::HTTP.new(uri.host, uri.inferred_port) - http.read_timeout = PenderConfig.get('timeout', 30).to_i - http.use_ssl = uri.scheme == 'https'.freeze + http = self.initialize_http(uri) headers = { 'User-Agent' => self.html_options(uri)['User-Agent'], 'Accept-Language' => LANG, @@ -149,15 +147,20 @@ def request_uri(uri, verb = 'Get') request = "Net::HTTP::#{verb}".constantize.new(uri.to_s, headers) request['Cookie'] = self.set_cookies(uri) + + http.request(request) + end + + def initialize_http(uri) + http = Net::HTTP.new(uri.host, uri.inferred_port) proxy_config = self.get_proxy(uri, :hash) if proxy_config - proxy = Net::HTTP::Proxy(proxy_config['host'], proxy_config['port'], proxy_config['user'], proxy_config['pass']) - proxy.start(uri.host, uri.inferred_port, use_ssl: uri.scheme == 'https') do |http2| - http2.request(request) - end - else - http.request(request) + http = Net::HTTP.new(uri.host, uri.inferred_port, proxy_config['host'], proxy_config['port'], proxy_config['user'], proxy_config['pass']) end + http.read_timeout = PenderConfig.get('timeout', 30).to_i + http.use_ssl = uri.scheme == 'https'.freeze + + http end def decode_uri(url) diff --git a/app/models/parser/tiktok_item.rb b/app/models/parser/tiktok_item.rb index ddf14c93..3f27cea2 100644 --- a/app/models/parser/tiktok_item.rb +++ b/app/models/parser/tiktok_item.rb @@ -54,8 +54,7 @@ def parse_data_for_parser(doc, _original_url, _jsonld_array) def get_tiktok_api_data(requested_url) uri = RequestHelper.parse_url(oembed_url) - http = Net::HTTP.new(uri.host, uri.inferred_port) - http.use_ssl = uri.scheme == 'https' + http = RequestHelper.initialize_http(uri) headers = RequestHelper.extended_headers(uri) request = Net::HTTP::Get.new(uri.request_uri, headers) response = http.request(request)