Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
This commit is contained in:
@@ -13,15 +13,14 @@ class ProviderDiscovery < OEmbed::ProviderDiscovery
|
||||
def discover_provider(url, **options)
|
||||
format = options[:format]
|
||||
|
||||
if options[:html]
|
||||
html = Nokogiri::HTML(options[:html])
|
||||
else
|
||||
res = Request.new(:get, url).perform
|
||||
|
||||
raise OEmbed::NotFound, url if res.code != 200 || res.mime_type != 'text/html'
|
||||
|
||||
html = Nokogiri::HTML(res.to_s)
|
||||
end
|
||||
html = if options[:html]
|
||||
Nokogiri::HTML(options[:html])
|
||||
else
|
||||
Request.new(:get, url).perform do |res|
|
||||
raise OEmbed::NotFound, url if res.code != 200 || res.mime_type != 'text/html'
|
||||
Nokogiri::HTML(res.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
if format.nil? || format == :json
|
||||
provider_endpoint ||= html.at_xpath('//link[@type="application/json+oembed"]')&.attribute('href')&.value
|
||||
|
||||
+12
-4
@@ -33,9 +33,17 @@ class Request
|
||||
end
|
||||
|
||||
def perform
|
||||
http_client.headers(headers).public_send(@verb, @url.to_s, @options)
|
||||
rescue => e
|
||||
raise e.class, "#{e.message} on #{@url}", e.backtrace[0]
|
||||
begin
|
||||
response = http_client.headers(headers).public_send(@verb, @url.to_s, @options)
|
||||
rescue => e
|
||||
raise e.class, "#{e.message} on #{@url}", e.backtrace[0]
|
||||
end
|
||||
|
||||
begin
|
||||
yield response
|
||||
ensure
|
||||
http_client.close
|
||||
end
|
||||
end
|
||||
|
||||
def headers
|
||||
@@ -88,7 +96,7 @@ class Request
|
||||
end
|
||||
|
||||
def http_client
|
||||
HTTP.timeout(:per_operation, timeout).follow(max_hops: 2)
|
||||
@http_client ||= HTTP.timeout(:per_operation, timeout).follow(max_hops: 2)
|
||||
end
|
||||
|
||||
class Socket < TCPSocket
|
||||
|
||||
Reference in New Issue
Block a user