Skip to content

Commit

Permalink
Small content_type refactoring.
Browse files Browse the repository at this point in the history
* Avoid setting charset twice if parameter is passed as string rather than symbol.
* No need to check for empty params hash, there always is :charset.

Tests still pass.
  • Loading branch information
rkh committed Oct 19, 2010
1 parent 1c82b9d commit a52541c
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/sinatra/base.rb
Expand Up @@ -130,13 +130,9 @@ def mime_type(type)
def content_type(type, params={})
mime_type = mime_type(type)
fail "Unknown media type: %p" % type if mime_type.nil?
params[:charset] ||= defined?(Encoding) ? Encoding.default_external.to_s.downcase : 'utf-8'
if params.any?
params = params.collect { |kv| "%s=%s" % kv }.join(', ')
response['Content-Type'] = [mime_type, params].join(";")
else
response['Content-Type'] = mime_type
end
params[:charset] ||= params.delete('charset') ||
defined?(Encoding) ? Encoding.default_external.to_s.downcase : 'utf-8'
response['Content-Type'] = "#{mime_type};#{params.map { |kv| kv.join('=') }.join(', ')}"
end

# Set the Content-Disposition to "attachment" with the specified filename,
Expand Down

0 comments on commit a52541c

Please sign in to comment.