Commit 740115d9 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu Committed by Douglas Barbosa Alexandre

Use media_type instead of content_type

In Rails 6, content_type now returns the complete header. We use
media_type to just get the MIME type portion

See https://github.com/rails/rails/pull/36034
parent 61b94b45
......@@ -120,7 +120,7 @@ class ApplicationController < ActionController::Base
def render(*args)
super.tap do
# Set a header for custom error pages to prevent them from being intercepted by gitlab-workhorse
if (400..599).cover?(response.status) && workhorse_excluded_content_types.include?(response.content_type)
if (400..599).cover?(response.status) && workhorse_excluded_content_types.include?(response.media_type)
response.headers['X-GitLab-Custom-Error'] = '1'
end
end
......
......@@ -41,14 +41,14 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'returns sha1 of the file' do
download_file(package_file.file_name + '.sha1')
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('text/plain')
expect(response.media_type).to eq('text/plain')
expect(response.body).to eq(package_file.file_sha1)
end
end
......@@ -67,7 +67,7 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'denies download when no private token' do
......@@ -80,7 +80,7 @@ describe API::MavenPackages do
download_file(package_file.file_name, job_token: job.token)
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
end
......@@ -97,7 +97,7 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'denies download when not enough permissions' do
......@@ -118,7 +118,7 @@ describe API::MavenPackages do
download_file(package_file.file_name, job_token: job.token)
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
end
......@@ -164,14 +164,14 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'returns sha1 of the file' do
download_file(package_file.file_name + '.sha1')
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('text/plain')
expect(response.media_type).to eq('text/plain')
expect(response.body).to eq(package_file.file_sha1)
end
end
......@@ -190,7 +190,7 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'denies download when no private token' do
......@@ -203,7 +203,7 @@ describe API::MavenPackages do
download_file(package_file.file_name, job_token: job.token)
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
end
......@@ -220,7 +220,7 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'denies download when not enough permissions' do
......@@ -241,7 +241,7 @@ describe API::MavenPackages do
download_file(package_file.file_name, job_token: job.token)
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
end
......@@ -272,14 +272,14 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'returns sha1 of the file' do
download_file(package_file.file_name + '.sha1')
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('text/plain')
expect(response.media_type).to eq('text/plain')
expect(response.body).to eq(package_file.file_sha1)
end
end
......@@ -297,7 +297,7 @@ describe API::MavenPackages do
subject
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
it 'denies download when not enough permissions' do
......@@ -318,7 +318,7 @@ describe API::MavenPackages do
download_file(package_file.file_name, job_token: job.token)
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream')
expect(response.media_type).to eq('application/octet-stream')
end
end
......@@ -351,7 +351,7 @@ describe API::MavenPackages do
authorize_upload_with_token
expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
expect(json_response['TempPath']).not_to be_nil
end
......
......@@ -37,10 +37,10 @@ module Gitlab
controller = env[CONTROLLER_KEY]
action = "#{controller.class.name}##{controller.action_name}"
if controller.content_type == 'text/html'
if controller.media_type == 'text/html'
action
else
"#{action} (#{controller.content_type})"
"#{action} (#{controller.media_type})"
end
end
......
......@@ -26,7 +26,7 @@ describe Gitlab::QueryLimiting::Middleware do
:controller,
action_name: 'show',
class: double(:class, name: 'UsersController'),
content_type: 'text/html'
media_type: 'text/html'
)
}
......@@ -39,7 +39,7 @@ describe Gitlab::QueryLimiting::Middleware do
:controller,
action_name: 'show',
class: double(:class, name: 'UsersController'),
content_type: 'application/json'
media_type: 'application/json'
)
}
......
......@@ -62,7 +62,7 @@ module JavaScriptFixturesHelpers
fixture = response.body
fixture.force_encoding("utf-8")
response_mime_type = Mime::Type.lookup(response.content_type)
response_mime_type = Mime::Type.lookup(response.media_type)
if response_mime_type.html?
doc = Nokogiri::HTML::DocumentFragment.parse(fixture)
......
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