Mongrel / WEBRick creation serves static assets with a heading for future expiration

I am creating a Rails application that will be deployed on desktop computers running both a web server and a browser (this is a test application that should work without an Internet connection).

For this reason, I will run Mongrel or WEBRick, without Apache / Nginx in front of you, as usual. The browser will directly contact Mongrel.

The problem I am facing right now is that it takes some time to load resources (javascript / stylesheets / images). I usually fix this by setting future expiration dates for these assets in the Apache proxy to Mongrel / WEBRick, so that assets are requested only once, and then only one request is required per action.

But in this case, the proxy does not exist, and I use config.serve_static_assets = true

So the question is: can Mongrel / WEBrick be said to hit expiration headers on static assets?

I am using Rails 3 on Ruby 1.9.2.

+4
source share
1 answer

you can try something like this:

  def get(path) @headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain" unless path.include? ".." # prevent directory traversal attacks @headers['X-Sendfile'] = "#{PATH}/static/#{path}" else @status = 403 # "403 - Invalid path" end end 
+1
source

Source: https://habr.com/ru/post/1343317/


All Articles