Skip to content

Commit

Permalink
Merge pull request #1161 from bdunne/fix_download_metadata
Browse files Browse the repository at this point in the history
Add some logic for following redirects
  • Loading branch information
Fryguy authored Oct 11, 2023
2 parents a289b67 + 76bad50 commit 67cdf93
Showing 1 changed file with 11 additions and 7 deletions.
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

0 comments on commit 67cdf93

Please sign in to comment.