0
@@ -24,7 +24,8 @@ module ActionController #:nodoc:
0
# * <tt>:filename</tt> - suggests a filename for the browser to use.
0
# Defaults to <tt>File.basename(path)</tt>.
0
- # * <tt>:type</tt> - specifies an HTTP content type. Defaults to 'application/octet-stream'.
0
+ # * <tt>:type</tt> - specifies an HTTP content type. Defaults to 'application/octet-stream'. You can specify
0
+ # either a string or a symbol for a registered type register with <tt>Mime::Type.register</tt>, for example :json
0
# * <tt>:length</tt> - used to manually override the length (in bytes) of the content that
0
# is going to be sent to the client. Defaults to <tt>File.size(path)</tt>.
0
# * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded.
0
@@ -107,7 +108,8 @@ module ActionController #:nodoc:
0
# * <tt>:filename</tt> - suggests a filename for the browser to use.
0
- # * <tt>:type</tt> - specifies an HTTP content type. Defaults to 'application/octet-stream'.
0
+ # * <tt>:type</tt> - specifies an HTTP content type. Defaults to 'application/octet-stream'. You can specify
0
+ # either a string or a symbol for a registered type register with <tt>Mime::Type.register</tt>, for example :json
0
# * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded.
0
# Valid values are 'inline' and 'attachment' (default).
0
# * <tt>:status</tt> - specifies the status code to send with the response. Defaults to '200 OK'.
0
@@ -143,9 +145,16 @@ module ActionController #:nodoc:
0
disposition <<= %(; filename="#{options[:filename]}") if options[:filename]
0
+ content_type = options[:type]
0
+ if content_type.is_a?(Symbol)
0
+ raise ArgumentError, "Unknown MIME type #{options[:type]}" unless Mime::EXTENSION_LOOKUP.has_key?(content_type.to_s)
0
+ content_type = Mime::Type.lookup_by_extension(content_type.to_s)
0
+ content_type = content_type.to_s.strip # fixes a problem with extra '\r' with some browsers
0
'Content-Length' => options[:length],
0
- 'Content-Type' =>
options[:type].to_s.strip, # fixes a problem with extra '\r' with some browsers0
+ 'Content-Type' =>
content_type,0
'Content-Disposition' => disposition,
0
'Content-Transfer-Encoding' => 'binary'