def callcall(env)
accept, index = env['rack-accept.request'], {}
if env['rack.request.query_hash']["format"]
media_type = case env['rack.request.query_hash']["format"]
when 'html' then :html
when 'xml' then :xml
when 'json' then :json
when 'gv' then :gv
when 'png' then :png
end
index[media_type] = 1 if media_type
else
sorted_media_types = accept.media_type.qvalues.to_a.sort{ |a,b| a[1]<=>b[1] }.collect { |t| t.first }
sorted_media_types << 'application/xml' if sorted_media_types.empty?
ACCEPTED_MEDIA_TYPES.each do |format, definition|
definition[:match].each do |media_type|
break if index[format] = sorted_media_types.index(media_type)
end
end
index.reject! { |format, priority| not priority }
end
if index.keys.empty?
status, headers, response = 406, {}, ""
else
env['rack-accept.formats'] = index
status, headers, response = @app.call(env)
end
[status, headers, response]
end