mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Add extra safety
This commit is contained in:
parent
2c59ad3dd3
commit
4e37bcc3e2
1 changed files with 20 additions and 10 deletions
|
@ -93,18 +93,28 @@ class StaticController < ApplicationController
|
||||||
# a huge expiry, we also cache these assets in nginx so it bypassed if needed
|
# a huge expiry, we also cache these assets in nginx so it bypassed if needed
|
||||||
def favicon
|
def favicon
|
||||||
|
|
||||||
data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60*60*24) do
|
data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60*30) do
|
||||||
file = FileHelper.download(SiteSetting.favicon_url, 50.kilobytes, "favicon.png")
|
begin
|
||||||
data = file.read
|
file = FileHelper.download(SiteSetting.favicon_url, 50.kilobytes, "favicon.png")
|
||||||
file.unlink
|
data = file.read
|
||||||
data
|
file.unlink
|
||||||
|
data
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.warn("Invalid favicon_url #{SiteSetting.favicon_url}: #{e}\n#{e.backtrace}")
|
||||||
|
""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.bytesize == 0
|
||||||
|
render text: UserAvatarsController::DOT, content_type: "image/gif"
|
||||||
|
else
|
||||||
|
expires_in 1.year, public: true
|
||||||
|
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 text: data, content_type: "image/png"
|
||||||
end
|
end
|
||||||
|
|
||||||
expires_in 1.year, public: true
|
|
||||||
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 text: data, content_type: "image/png"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue