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