Skip to content
Browse files

implement code that handles text/*, appplication/*,

and image/*

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent b798a59 commit 6f6e754bac4c78f657feb0ea119447546aa87197 Neeraj Singh committed with josevalim Nov 22, 2010
Showing with 16 additions and 1 deletion.
  1. +16 −1 actionpack/lib/action_dispatch/http/mime_type.rb
View
17 actionpack/lib/action_dispatch/http/mime_type.rb
@@ -103,9 +103,14 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last }
end
+
def parse(accept_header)
if accept_header !~ /,/
- [Mime::Type.lookup(accept_header)]
+ if result = Regexp.new('(\w+)\/\*').match(accept_header)
+ parse_data_with_trailing_star(result[1])
+ else
+ [Mime::Type.lookup(accept_header)]
+ end
else
# keep track of creation order to keep the subsequent sort stable
list = []
@@ -160,6 +165,16 @@ def parse(accept_header)
list
end
end
+
+ # input: 'text'
+ # returend value: [Mime::JSON, Mime::XML, Mime::ICS, Mime::HTML, Mime::CSS, Mime::CSV, Mime::JS, Mime::YAML, Mime::TEXT]
@nertzy
nertzy added a note Dec 13, 2010

typo: returend -> returned

@neerajdotname
Ruby on Rails member

Someone already fixed it already. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ #
+ # input: 'application'
+ # returend value: [Mime::HTML, Mime::JS, Mime::XML, Mime::YAML, Mime::ATOM, Mime::JSON, Mime::RSS, Mime::URL_ENCODED_FORM
+ def parse_data_with_trailing_star(input)
+ keys = Mime::LOOKUP.keys.select{|k| Regexp.new(input).match(k)}
+ Mime::LOOKUP.select {|k,_| keys.include?(k)}.collect{|i| i[1]}.inject([]){|all,e| all.include?(e) ? all : all << e}
+ end
end
def initialize(string, symbol = nil, synonyms = [])

0 comments on commit 6f6e754

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