Permalink
Browse files

special cased */* accept header

  • Loading branch information...
1 parent 95274b0 commit 02a67bc547c0d90565cb0a8a2b0ead95a7e6238b @daneharrigan committed Apr 16, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/respond_with/response.rb
@@ -27,7 +27,7 @@ def request_types
format = params.delete "format"
content_type = MIME::Types.type_for(format).first.to_s if format
- unless content_type.nil? && request.accept.first == content_type
+ if content_type && request.accept.first != content_type
request.accept.delete content_type
request.accept.unshift content_type
end
@@ -39,11 +39,18 @@ def request_types
def available_responses
responses = request_types.map do |request_type|
- if @object.responses.include? request_type
+ if @object.responses.include?(request_type)
[request_type, 1.0]
end
end.compact
+ if request_types.include? "*/*"
+ @object.responses.each do |response_type|
+ response_rating = [response_type, 1.0]
+ responses << response_rating unless responses.include? response_rating
+ end
+ end
+
Hash[responses]
end

0 comments on commit 02a67bc

Please sign in to comment.