2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

PERF: include content-length header for CDN

Attempt to force NGINX to include content length when doing X-SendFile
This does not seem to be required when bypassing NGINX.

Without this header some CDNs may have issues caching
This commit is contained in:
Sam 2019-02-22 11:21:07 +11:00
parent 31d41f532e
commit 667d3a3fd6
2 changed files with 3 additions and 0 deletions

View file

@ -28,6 +28,8 @@ class ThemeJavascriptsController < ApplicationController
File.write(cache_file, content) File.write(cache_file, content)
end end
# this is only required for NGINX X-SendFile it seems
response.headers["Content-Length"] = File.size(cache_file).to_s
set_cache_control_headers set_cache_control_headers
send_file(cache_file, disposition: :inline) send_file(cache_file, disposition: :inline)
end end

View file

@ -40,6 +40,7 @@ describe ThemeJavascriptsController do
get "/theme-javascripts/#{javascript_cache.digest}.js" get "/theme-javascripts/#{javascript_cache.digest}.js"
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(response.body).to eq(javascript_cache.content) expect(response.body).to eq(javascript_cache.content)
expect(response.headers['Content-Length']).to eq(javascript_cache.content.bytesize.to_s)
javascript_cache.destroy! javascript_cache.destroy!