Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a content-type for a specific file with Rack?

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.

like image 783
Sven Koschnicke Avatar asked Jul 22 '10 14:07

Sven Koschnicke


People also ask

How do I change the contents of a file type?

Go to the document library in which you want to update the content type with a document template. On the Ribbon, click the Library tab, and then click Library Settings. Under Content Types, click the name of the content type that you want to change.

What is MIME type files?

A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

What is MIME type in HTML?

A MIME type (or media type) is an identifier for file formats or format contents on the Internet. MIME stands for Multipurpose Internet Mail Extensions and all MIME types are officially maintained by the Internet Assigned Numbers Authority (IANA).

How is MIME type determined?

MIME types are defined by three attributes: language (lang), encoding (enc), and content-type (type). At least one of these attributes must be present for each type. The most commonly used attribute is type. The server frequently considers the type when deciding how to generate the response to the client.


1 Answers

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"
})
like image 193
jigfox Avatar answered Sep 19 '22 18:09

jigfox