mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-25 07:23:43 +01:00
Improve redirect handling in FetchAtomService
This commit is contained in:
parent
c6b0311b86
commit
210362e665
2 changed files with 5 additions and 4 deletions
|
@ -8,7 +8,7 @@ class FetchAtomService < BaseService
|
||||||
if response.mime_type == 'application/atom+xml'
|
if response.mime_type == 'application/atom+xml'
|
||||||
return [url, fetch(url)]
|
return [url, fetch(url)]
|
||||||
elsif !response['Link'].blank?
|
elsif !response['Link'].blank?
|
||||||
return process_headers(response)
|
return process_headers(url, response)
|
||||||
else
|
else
|
||||||
return process_html(fetch(url))
|
return process_html(fetch(url))
|
||||||
end
|
end
|
||||||
|
@ -26,13 +26,13 @@ class FetchAtomService < BaseService
|
||||||
return [alternate_link['href'], fetch(alternate_link['href'])]
|
return [alternate_link['href'], fetch(alternate_link['href'])]
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_headers(response)
|
def process_headers(url, response)
|
||||||
Rails.logger.debug "Processing link header"
|
Rails.logger.debug "Processing link header"
|
||||||
|
|
||||||
link_header = LinkHeader.parse(response['Link'])
|
link_header = LinkHeader.parse(response['Link'])
|
||||||
alternate_link = link_header.find_link(['rel', 'alternate'], ['type', 'application/atom+xml'])
|
alternate_link = link_header.find_link(['rel', 'alternate'], ['type', 'application/atom+xml'])
|
||||||
|
|
||||||
return nil if alternate_link.nil?
|
return process_html(fetch(url)) if alternate_link.nil?
|
||||||
return [alternate_link.href, fetch(alternate_link.href)]
|
return [alternate_link.href, fetch(alternate_link.href)]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,6 +41,6 @@ class FetchAtomService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def http_client
|
def http_client
|
||||||
HTTP.timeout(:per_operation, write: 20, connect: 20, read: 50)
|
HTTP.timeout(:per_operation, write: 20, connect: 20, read: 50).follow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ class FetchRemoteAccountService < BaseService
|
||||||
private
|
private
|
||||||
|
|
||||||
def process_atom(url, body)
|
def process_atom(url, body)
|
||||||
|
xml = Nokogiri::XML(body)
|
||||||
url_parts = Addressable::URI.parse(url)
|
url_parts = Addressable::URI.parse(url)
|
||||||
username = xml.at_xpath('//xmlns:author/xmlns:name').try(:content)
|
username = xml.at_xpath('//xmlns:author/xmlns:name').try(:content)
|
||||||
domain = url_parts.host
|
domain = url_parts.host
|
||||||
|
|
Loading…
Reference in a new issue