Skip to content

Instantly share code, notes, and snippets.

@adriand
Created February 16, 2010 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adriand/305855 to your computer and use it in GitHub Desktop.
Save adriand/305855 to your computer and use it in GitHub Desktop.
# The media type parameters provided in CONTENT_TYPE as a Hash, or
# an empty Hash if no CONTENT_TYPE or media-type parameters were
# provided. e.g., when the CONTENT_TYPE is "text/plain;charset=utf-8",
# this method responds with the following Hash:
# { 'charset' => 'utf-8' }
def media_type_params
return {} if content_type.nil?
content_type.split(/\s*[;,]\s*/)[1..-1].
collect { |s| s.split('=', 2) }.
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment