For assets stored in the 'public' folder of a ruby-on-rails application is it possible to change the 'Content-Type' when running 'script/server'? For example, I am attempting to create an HTML5 application supporting offline mode, and have an 'offline.manifest'. When I run:
curl -I localhost:3000/offline.mainfest
The following header information is returned:
HTTP/1.1 200 OK
...
Content-Type: text/plain
...
However, HTML5 specifications require:
HTTP/1.1 200 OK
...
Content-Type: text/cache-manifest
...
As of Rails 5, putting this in an initializer works:
Rack::Mime::MIME_TYPES[".manifest"]="text/cache-manifest"
I'm not sure about other versions.
n.b. that it will not work to do Mime::Type.register "text/cache-manifest", :manifest
— this is only for rails controllers.
I'm not sure if Rails::Rack::Static
is used anywhere in Rails. Rails uses ActionDispatch::Static
, which doesn't inherit from Rails::Rack::Static
or anything like that. But it does use several things from Rack
, including Rack::Mime
, which is (i think?) completely separate from Mime
which is used elsewhere in Rails.
source for ActionDispatch::Static
: https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/static.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With