mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
favicon proxy now uses hijack
This commit is contained in:
@ -100,34 +100,36 @@ class StaticController < ApplicationController
|
||||
# a huge expiry, we also cache these assets in nginx so it bypassed if needed
|
||||
def favicon
|
||||
|
||||
data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60 * 30) do
|
||||
begin
|
||||
file = FileHelper.download(
|
||||
SiteSetting.favicon_url,
|
||||
max_file_size: 50.kilobytes,
|
||||
tmp_file_name: "favicon.png",
|
||||
follow_redirect: true
|
||||
)
|
||||
data = file.read
|
||||
file.unlink
|
||||
data
|
||||
rescue => e
|
||||
AdminDashboardData.add_problem_message('dashboard.bad_favicon_url', 1800)
|
||||
Rails.logger.debug("Invalid favicon_url #{SiteSetting.favicon_url}: #{e}\n#{e.backtrace}")
|
||||
""
|
||||
hijack do
|
||||
data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60 * 30) do
|
||||
begin
|
||||
file = FileHelper.download(
|
||||
SiteSetting.favicon_url,
|
||||
max_file_size: 50.kilobytes,
|
||||
tmp_file_name: "favicon.png",
|
||||
follow_redirect: true
|
||||
)
|
||||
data = file.read
|
||||
file.unlink
|
||||
data
|
||||
rescue => e
|
||||
AdminDashboardData.add_problem_message('dashboard.bad_favicon_url', 1800)
|
||||
Rails.logger.debug("Invalid favicon_url #{SiteSetting.favicon_url}: #{e}\n#{e.backtrace}")
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if data.bytesize == 0
|
||||
@@default_favicon ||= File.read(Rails.root + "public/images/default-favicon.png")
|
||||
response.headers["Content-Length"] = @@default_favicon.bytesize.to_s
|
||||
render plain: @@default_favicon, content_type: "image/png"
|
||||
else
|
||||
immutable_for 1.year
|
||||
response.headers["Expires"] = 1.year.from_now.httpdate
|
||||
response.headers["Content-Length"] = data.bytesize.to_s
|
||||
response.headers["Last-Modified"] = Time.new('2000-01-01').httpdate
|
||||
render plain: data, content_type: "image/png"
|
||||
if data.bytesize == 0
|
||||
@@default_favicon ||= File.read(Rails.root + "public/images/default-favicon.png")
|
||||
response.headers["Content-Length"] = @@default_favicon.bytesize.to_s
|
||||
render body: @@default_favicon, content_type: "image/png"
|
||||
else
|
||||
immutable_for 1.year
|
||||
response.headers["Expires"] = 1.year.from_now.httpdate
|
||||
response.headers["Content-Length"] = data.bytesize.to_s
|
||||
response.headers["Last-Modified"] = Time.new('2000-01-01').httpdate
|
||||
render body: data, content_type: "image/png"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user