Skip to content

Commit

Permalink
implement code that handles text/*, appplication/*,
Browse files Browse the repository at this point in the history
and image/*

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
Neeraj Singh authored and josevalim committed Nov 22, 2010
1 parent b798a59 commit 6f6e754
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion actionpack/lib/action_dispatch/http/mime_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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]

This comment has been minimized.

Copy link
@nertzy

nertzy Dec 13, 2010

Contributor

typo: returend -> returned

This comment has been minimized.

Copy link
@neerajsingh0101

neerajsingh0101 Dec 13, 2010

Someone already fixed it already. :-)

#
# 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 = [])
Expand Down

0 comments on commit 6f6e754

Please sign in to comment.