The response_content_type extension adds response.content_type and response.content_type= methods for getting and setting the response content-type.
When setting the content-type, you can pass either a string, which is used directly:
response.content_type = "text/html"
Or, if you have registered mime types when loading the plugin:
plugin :response_content_type, mime_types: { plain: "text/plain", html: "text/html", pdf: "application/pdf" }
You can use a symbol:
response.content_type = :html
If you would like to load all mime types supported by rack/mime, you can use the mime_types: :from_rack_mime
option:
plugin :response_content_type, mime_types: :from_rack_mime
Note that you are unlikely to be using all of these mime types, so doing this will likely result in unnecessary memory usage. It is recommended to use a hash with only the mime types your application actually uses.
To prevent silent failures, if you attempt to set the response type with a symbol, and the symbol is not recognized, a KeyError is raised.
Classes and Modules
Public Class methods
# File lib/roda/plugins/response_content_type.rb 41 def self.configure(app, opts=OPTS) 42 if mime_types = opts[:mime_types] 43 mime_types = if mime_types == :from_rack_mime 44 require "rack/mime" 45 h = {} 46 Rack::Mime::MIME_TYPES.each do |k, v| 47 h[k.slice(1,100).to_sym] = v 48 end 49 h 50 else 51 mime_types.dup 52 end 53 app.opts[:repsonse_content_types] = mime_types.freeze 54 else 55 app.opts[:repsonse_content_types] ||= {} 56 end 57 end