11

I want to have Rack serve a specific file with a specific content type. It's a .htc file and it needs to be served as text/x-component so that IE will recognize it. In apache I would just do

AddType text/x-component .htc

How can I achieve this with Rack? Currently the file is served by Rack::Static, but I didn't find an option to set the content type.

Andy E
  • 338,112
  • 86
  • 474
  • 445
Sven Koschnicke
  • 6,523
  • 2
  • 34
  • 49

2 Answers2

15

You can update your config/initializers/mime_types.rb like this:

# Be sure to restart your server when you modify this file.

# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone

Rack::Mime::MIME_TYPES.merge!({
  ".ogg"     => "application/ogg",
  ".ogx"     => "application/ogg",
  ".ogv"     => "video/ogg",
  ".oga"     => "audio/ogg",
  ".mp4"     => "video/mp4",
  ".m4v"     => "video/mp4",
  ".mp3"     => "audio/mpeg",
  ".m4a"     => "audio/mpeg",
  ".htc"     => "text/x-component"
})
jigfox
  • 18,057
  • 3
  • 60
  • 73
0

Or just to reply to the question, add this in config/initializers/mime_types.rb:

Mime::Type.register "text/x-component", :htc
Dorian
  • 22,759
  • 8
  • 120
  • 116