Clean up content type and add Expires header when serving CDN assets

This commit is contained in:
Sam 2014-10-21 15:59:16 +11:00
parent 4eb1288dba
commit 4e7057efb1

View file

@ -86,16 +86,21 @@ class StaticController < ApplicationController
end end
expires_in 1.year, public: true expires_in 1.year, public: true
response.headers["Expires"] = 1.year.from_now.httpdate
response.headers["Access-Control-Allow-Origin"] = params[:origin] response.headers["Access-Control-Allow-Origin"] = params[:origin]
begin begin
response.headers["Last-Modified"] = File.ctime(path).httpdate response.headers["Last-Modified"] = File.ctime(path).httpdate
response.headers["Content-Length"] = File.size(path)
rescue Errno::ENOENT rescue Errno::ENOENT
raise Discourse::NotFound raise Discourse::NotFound
end end
opts = { opts = {
disposition: nil disposition: nil
} }
opts[:type] = "application/x-javascript" if path =~ /\.js$/
opts[:type] = "application/javascript" if path =~ /\.js$/
# we must disable acceleration otherwise NGINX strips # we must disable acceleration otherwise NGINX strips
# access control headers # access control headers