Commit 14e35ac9 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'blackst0ne-rails5-set-request-format-in--commits-controller' into 'master'

[Rails5] Set request.format in commits_controller

Closes #48144 et #48143

See merge request gitlab-org/gitlab-ce!20023
parents 60f51cd2 6da19415
...@@ -9,6 +9,7 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -9,6 +9,7 @@ class Projects::CommitsController < Projects::ApplicationController
before_action :assign_ref_vars before_action :assign_ref_vars
before_action :authorize_download_code! before_action :authorize_download_code!
before_action :set_commits before_action :set_commits
before_action :set_request_format, only: :show
def show def show
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened @merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
...@@ -61,6 +62,19 @@ class Projects::CommitsController < Projects::ApplicationController ...@@ -61,6 +62,19 @@ class Projects::CommitsController < Projects::ApplicationController
@commits = prepare_commits_for_rendering(@commits) @commits = prepare_commits_for_rendering(@commits)
end end
# Rails 5 sets request.format from the extension.
# Explicitly set to :html.
def set_request_format
request.format = :html if set_request_format?
end
# Rails 5 sets request.format from extension.
# In this case if the ref ends with `.atom`, it's expected to be the html response,
# not the atom one. So explicitly set request.format as :html to act like rails4.
def set_request_format?
request.format.to_s == "text/html" || @commits.ref.ends_with?("atom")
end
def whitelist_query_limiting def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42330') Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42330')
end end
......
---
title: "[Rails5] Set request.format in commits_controller"
merge_request: 20023
author: "@blackst0ne"
type: fixed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment