Skip to content

Commit

Permalink
Added application/jsonrequest as a synonym for application/json
Browse files Browse the repository at this point in the history
[#536 state:resolved]
  • Loading branch information
subelsky authored and technoweenie committed Jul 2, 2008
1 parent a4138d4 commit 8f640c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion actionpack/lib/action_controller/mime_types.rb
Expand Up @@ -17,4 +17,5 @@
Mime::Type.register "application/x-www-form-urlencoded", :url_encoded_form

# http://www.ietf.org/rfc/rfc4627.txt
Mime::Type.register "application/json", :json, %w( text/x-json )
# http://www.json.org/JSONRequest.html
Mime::Type.register "application/json", :json, %w( text/x-json application/jsonrequest )
14 changes: 10 additions & 4 deletions actionpack/test/controller/request_test.rb
Expand Up @@ -909,15 +909,21 @@ def parse_body(body)
end

class JsonParamsParsingTest < Test::Unit::TestCase
def test_hash_params
person = parse_body({:person => {:name => "David"}}.to_json)[:person]
def test_hash_params_for_application_json
person = parse_body({:person => {:name => "David"}}.to_json,'application/json')[:person]
assert_kind_of Hash, person
assert_equal 'David', person['name']
end

def test_hash_params_for_application_jsonrequest
person = parse_body({:person => {:name => "David"}}.to_json,'application/jsonrequest')[:person]
assert_kind_of Hash, person
assert_equal 'David', person['name']
end

private
def parse_body(body)
env = { 'CONTENT_TYPE' => 'application/json',
def parse_body(body,content_type)
env = { 'CONTENT_TYPE' => content_type,
'CONTENT_LENGTH' => body.size.to_s }
cgi = ActionController::Integration::Session::StubCGI.new(env, body)
ActionController::CgiRequest.new(cgi).request_parameters
Expand Down

0 comments on commit 8f640c3

Please sign in to comment.