Skip to content

Commit

Permalink
Add some logic for following redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Oct 11, 2023
1 parent a289b67 commit 76bad50
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 76bad50

Please sign in to comment.