mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 06:41:25 +08:00
DEV: Remove legacy /brotli_asset
workaround (#24243)
When Discourse first introduced brotli support, reverse-proxy/CDN support for passing through the accept-encoding header to our NGINX server was very poor. Therefore, a separate `/brotli_assets/...` path was introduced to serve the brotli assets. This worked well, but introduces additional complexity and inconsistencies. Nowadays, Brotli encoding is well supported, so we don't need the separate paths any more. Requests can be routed to the asset `.js` URLs, and NGINX will serve the brotli/gzip version of the asset automatically.
This commit is contained in:
@ -57,89 +57,6 @@ RSpec.describe StaticController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#brotli_asset" do
|
||||
it "returns a non brotli encoded 404 if asset is missing" do
|
||||
get "/brotli_asset/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=1/)
|
||||
end
|
||||
|
||||
it "can handle fallback brotli assets" do
|
||||
begin
|
||||
assets_path = Rails.root.join("tmp/backup_assets")
|
||||
|
||||
GlobalSetting.stubs(:fallback_assets_path).returns(assets_path.to_s)
|
||||
|
||||
FileUtils.mkdir_p(assets_path)
|
||||
|
||||
file_path = assets_path.join("test.js.br")
|
||||
File.write(file_path, "fake brotli file")
|
||||
|
||||
get "/brotli_asset/test.js"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.headers["Cache-Control"]).to match(/public/)
|
||||
ensure
|
||||
File.delete(file_path)
|
||||
end
|
||||
end
|
||||
|
||||
it "has correct headers for brotli assets" do
|
||||
begin
|
||||
assets_path = Rails.root.join("public/assets")
|
||||
|
||||
FileUtils.mkdir_p(assets_path)
|
||||
|
||||
file_path = assets_path.join("test.js.br")
|
||||
File.write(file_path, "fake brotli file")
|
||||
|
||||
get "/brotli_asset/test.js"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.headers["Cache-Control"]).to match(/public/)
|
||||
ensure
|
||||
File.delete(file_path)
|
||||
end
|
||||
end
|
||||
|
||||
it "has correct cors headers for brotli assets" do
|
||||
begin
|
||||
assets_path = Rails.root.join("public/assets")
|
||||
|
||||
FileUtils.mkdir_p(assets_path)
|
||||
|
||||
file_path = assets_path.join("test.js.br")
|
||||
File.write(file_path, "fake brotli file")
|
||||
GlobalSetting.stubs(:cdn_url).returns("https://www.example.com/")
|
||||
|
||||
get "/brotli_asset/test.js"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.headers["Access-Control-Allow-Origin"]).to match("*")
|
||||
ensure
|
||||
File.delete(file_path)
|
||||
end
|
||||
end
|
||||
|
||||
it "can serve sourcemaps on adjacent paths" do
|
||||
assets_path = Rails.root.join("public/assets")
|
||||
|
||||
FileUtils.mkdir_p(assets_path)
|
||||
|
||||
file_path = assets_path.join("test.map")
|
||||
File.write(file_path, "fake source map")
|
||||
GlobalSetting.stubs(:cdn_url).returns("https://www.example.com/")
|
||||
|
||||
get "/brotli_asset/test.map"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
ensure
|
||||
File.delete(file_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#cdn_asset" do
|
||||
let (:site) {
|
||||
RailsMultisite::ConnectionManagement.current_db
|
||||
|
Reference in New Issue
Block a user