mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-21 18:05:23 -05:00
Non-ActivityPub Link header alternate blocks HTML ActivityPub discovery in FetchResourceService (#37439)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
122b1592ed
commit
c6be114cef
|
|
@ -58,13 +58,7 @@ class FetchResourceService < BaseService
|
|||
|
||||
[@url, { prefetched_body: body }]
|
||||
elsif !terminal
|
||||
link_header = response['Link'] && parse_link_header(response)
|
||||
|
||||
if link_header&.find_link(%w(rel alternate))
|
||||
process_link_headers(link_header)
|
||||
elsif response.mime_type == 'text/html'
|
||||
process_html(response)
|
||||
end
|
||||
process_link_headers(response) || process_html(response)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -73,13 +67,18 @@ class FetchResourceService < BaseService
|
|||
end
|
||||
|
||||
def process_html(response)
|
||||
return unless response.mime_type == 'text/html'
|
||||
|
||||
page = Nokogiri::HTML5(response.body_with_limit)
|
||||
json_link = page.xpath('//link[nokogiri:link_rel_include(@rel, "alternate")]', NokogiriHandler).find { |link| ACTIVITY_STREAM_LINK_TYPES.include?(link['type']) }
|
||||
|
||||
process(json_link['href'], terminal: true) unless json_link.nil?
|
||||
end
|
||||
|
||||
def process_link_headers(link_header)
|
||||
def process_link_headers(response)
|
||||
link_header = response['Link'] && parse_link_header(response)
|
||||
return if link_header.nil?
|
||||
|
||||
json_link = link_header.find_link(%w(rel alternate), %w(type application/activity+json)) || link_header.find_link(%w(rel alternate), ['type', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'])
|
||||
|
||||
process(json_link.href, terminal: true) unless json_link.nil?
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user