mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 17:06:31 -06:00
FIX: on 404 from brotli asset path return a correctly encoded doc
old implementation would cache the 404 for 1 year with incorrect encoding hilarity would ensue
This commit is contained in:
parent
f867af6bf9
commit
98f4a2adcb
@ -135,23 +135,25 @@ class StaticController < ApplicationController
|
|||||||
opts = { disposition: nil }
|
opts = { disposition: nil }
|
||||||
opts[:type] = "application/javascript" if path =~ /\.js.br$/
|
opts[:type] = "application/javascript" if path =~ /\.js.br$/
|
||||||
|
|
||||||
response.headers["Expires"] = 1.year.from_now.httpdate
|
|
||||||
response.headers["Cache-Control"] = 'max-age=31557600, public'
|
|
||||||
response.headers["Content-Encoding"] = 'br'
|
|
||||||
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).to_s
|
response.headers["Content-Length"] = File.size(path).to_s
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
raise Discourse::NotFound
|
response.headers["Expires"] = 5.seconds.from_now.httpdate
|
||||||
|
response.headers["Cache-Control"] = 'max-age=5, public'
|
||||||
|
expires_in 5.seconds, public: true, must_revalidate: false
|
||||||
|
|
||||||
|
render text: "missing brotli asset", status: 404
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
response.headers["Expires"] = 1.year.from_now.httpdate
|
||||||
|
response.headers["Cache-Control"] = 'max-age=31557600, public'
|
||||||
|
response.headers["Content-Encoding"] = 'br'
|
||||||
|
|
||||||
expires_in 1.year, public: true, must_revalidate: false
|
expires_in 1.year, public: true, must_revalidate: false
|
||||||
|
|
||||||
if File.exists?(path)
|
send_file(path, opts)
|
||||||
send_file(path, opts)
|
|
||||||
else
|
|
||||||
raise Discourse::NotFound
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,15 @@ require 'rails_helper'
|
|||||||
describe StaticController do
|
describe StaticController do
|
||||||
|
|
||||||
context 'brotli_asset' do
|
context 'brotli_asset' do
|
||||||
|
it 'returns a brotli encoded 404 if asset is missing' do
|
||||||
|
|
||||||
|
get :brotli_asset, path: 'missing.js'
|
||||||
|
|
||||||
|
expect(response.status).to eq(404)
|
||||||
|
expect(response.headers['Content-Encoding']).not_to eq('br')
|
||||||
|
expect(response.headers["Cache-Control"]).to match(/max-age=5/)
|
||||||
|
end
|
||||||
|
|
||||||
it 'has correct headers for brotli assets' do
|
it 'has correct headers for brotli assets' do
|
||||||
begin
|
begin
|
||||||
assets_path = Rails.root.join("public/assets")
|
assets_path = Rails.root.join("public/assets")
|
||||||
|
Loading…
Reference in New Issue
Block a user