Change Request#media_type to return nil

When the request don't have a Content-Type header we were returning
an empty string instead of nil like Rack does.
This commit is contained in:
Rafael Mendonça França 2021-01-26 23:24:27 +00:00
parent 13a96dd76e
commit a2efdf5577
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
3 changed files with 5 additions and 3 deletions

@ -1,4 +1,6 @@
## Unreleased
* Change `ActionDispatch::Request#media_type` to return `nil` when the request don't have a `Content-Type` header.
*Rafael Mendonça França*
* Fix error in `ActionController::LogSubscriber` that would happen when throwing inside a controller action.

@ -266,7 +266,7 @@ def original_url
# # get "/articles"
# request.media_type # => "application/x-www-form-urlencoded"
def media_type
content_mime_type.to_s
content_mime_type&.to_s
end
# Returns the content length of the request as an integer.

@ -1301,7 +1301,7 @@ class RequestFormData < BaseRequestTest
test "no Content-Type header is provided and the request_method is POST" do
request = stub_request("REQUEST_METHOD" => "POST")
assert_equal "", request.media_type
assert_nil request.media_type
assert_equal "POST", request.request_method
assert_not_predicate request, :form_data?
end