Skip to content
Browse files

Small content_type refactoring.

* 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...
1 parent 1c82b9d commit a52541c06eea52689092fbd45bb54fae690818f6 @rkh rkh committed Oct 19, 2010
Showing with 3 additions and 7 deletions.
  1. +3 −7 lib/sinatra/base.rb
View
10 lib/sinatra/base.rb
@@ -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,

0 comments on commit a52541c

Please sign in to comment.
Something went wrong with that request. Please try again.