Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some logic for following redirects #1161

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions site/_plugins/download_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ def file_info_from_url(url)
uri = URI(url)
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
response = http.request_head(uri.path)
if response.code != '200'
case response.code
when '200'
file_size = response['content-length'].to_f
{
"size" => ActiveSupport::NumberHelper.number_to_human_size(file_size),
"md5" => response['etag'].delete('"')
}
when '302'
Jekyll.logger.info("Following redirect for #{url}...")
file_info_from_url(response["location"])
else
Jekyll.logger.error("Jekyll::DownloadFilter.file_info_from_url(#{url})", "code=#{response.code}, message=#{response.message}")
return no_file_info
end

file_size = response['content-length'].to_f
return {
"size" => ActiveSupport::NumberHelper.number_to_human_size(file_size),
"md5" => response['etag'].delete('"')
}
end
rescue => error
Jekyll.logger.error("Jekyll::DownloadFilter.file_info_from_url(#{url})", "error=#{error.message}")
Expand Down