Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure ActionDispatch::Response#content_type behavior on Rails 6+ #2340

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

wasifhossain
Copy link
Member

@wasifhossain wasifhossain commented Jun 8, 2019

Purpose

This PR will affect all #content_type calls in the following files:

assert_equal 'application/json', @response.content_type

assert_equal 'application/json', @response.content_type

Background

Rails 6 changes the default behavior of ActionDispatch::Response#content_type, which now returns the Content-Type header as it is.

To retain old behavior, i.e. retrieve the mime type only, we can either set the following configuration in application settings:

config.action_dispatch.return_only_media_type_on_content_type = true

or set it inline as:

ActionDispatch::Response.return_only_media_type_on_content_type = true

or call #media_type instead of #content_type.

Additional helpful information

Rails 6.0 ACTIONPACK release notes:
https://github.com/rails/rails/blob/6-0-stable/actionpack/CHANGELOG.md

rails/rails#36490
rails/rails#36946

@wasifhossain wasifhossain requested a review from bf4 June 8, 2019 19:08
@wasifhossain wasifhossain force-pushed the action_dispatch_response_media_type branch from de5490a to 2f320ab Compare June 15, 2019 08:55
@wasifhossain
Copy link
Member Author

@bf4 I would like to have your thoughts on this. Not sure if this is the best way to handle the case.

@wasifhossain wasifhossain force-pushed the action_dispatch_response_media_type branch from 2f320ab to 7cc3e41 Compare August 23, 2019 16:50
in order to retain old behavior,
set `config.action_dispatch.return_only_media_type_on_content_type`
to true

it can also be configured by setting
`ActionDispatch::Response.return_only_media_type_on_content_type`
@wasifhossain wasifhossain force-pushed the action_dispatch_response_media_type branch from 7cc3e41 to 55a6b23 Compare August 23, 2019 17:47
@wasifhossain wasifhossain changed the title Use ActionDispatch::Response#media_type to retrieve mime_type in Rails 6+ Configure ActionDispatch::Response#content_type behavior on Rails 6+ Aug 23, 2019
@wasifhossain wasifhossain merged commit e349395 into 0-10-stable Aug 23, 2019
@wasifhossain wasifhossain deleted the action_dispatch_response_media_type branch August 23, 2019 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant