1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

View file

@ -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. * Fix error in `ActionController::LogSubscriber` that would happen when throwing inside a controller action.

View file

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

View file

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