diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-11-28 13:20:28 +0100 |
---|---|---|
committer | Francisco Javier López <fjlopez@gitlab.com> | 2018-11-28 13:20:28 +0100 |
commit | 87e0e3dc3d9f4da5b6b6a404caddd6d3adf49449 (patch) | |
tree | 343ec1bd70ac7a005d826a51427466917be2c56e | |
parent | d665de9cb1f00482cfaf247e01e34534ded352cc (diff) | |
download | gitlab-ce-fj-clean-content-headers.tar.gz |
Removed middleware and explicitly setting the workhorse headerfj-clean-content-headers
-rw-r--r-- | app/controllers/concerns/uploads_actions.rb | 1 | ||||
-rw-r--r-- | app/controllers/projects/jobs_controller.rb | 4 | ||||
-rw-r--r-- | config/application.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/middleware/workhorse_set_content_type_feature.rb | 37 | ||||
-rw-r--r-- | spec/lib/gitlab/middleware/workhorse_set_content_type_feature_spec.rb | 48 |
5 files changed, 3 insertions, 90 deletions
diff --git a/app/controllers/concerns/uploads_actions.rb b/app/controllers/concerns/uploads_actions.rb index 7a1c7abfb8f..3c928146073 100644 --- a/app/controllers/concerns/uploads_actions.rb +++ b/app/controllers/concerns/uploads_actions.rb @@ -44,6 +44,7 @@ module UploadsActions return render_404 unless uploader + workhorse_set_content_type! send_upload(uploader, attachment: uploader.filename, disposition: disposition) end diff --git a/app/controllers/projects/jobs_controller.rb b/app/controllers/projects/jobs_controller.rb index d31d46f0787..02116525ef2 100644 --- a/app/controllers/projects/jobs_controller.rb +++ b/app/controllers/projects/jobs_controller.rb @@ -139,6 +139,8 @@ class Projects::JobsController < Projects::ApplicationController end def raw + workhorse_set_content_type! + if trace_artifact_file send_upload(trace_artifact_file, send_params: raw_send_params, @@ -148,8 +150,6 @@ class Projects::JobsController < Projects::ApplicationController if stream.file? send_file stream.path, type: 'text/plain; charset=utf-8', disposition: 'inline' else - workhorse_set_content_type! - send_data stream.raw, type: 'text/plain; charset=utf-8', disposition: 'inline', filename: 'job.log' end end diff --git a/config/application.rb b/config/application.rb index 0a5b5fe1d71..921baa5d617 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,7 +20,6 @@ module Gitlab require_dependency Rails.root.join('lib/gitlab/current_settings') require_dependency Rails.root.join('lib/gitlab/middleware/read_only') require_dependency Rails.root.join('lib/gitlab/middleware/basic_health_check') - require_dependency Rails.root.join('lib/gitlab/middleware/workhorse_set_content_type_feature') # This needs to be loaded before DB connection is made # to make sure that all connections have NO_ZERO_DATE @@ -190,8 +189,6 @@ module Gitlab end end - config.middleware.insert_before Rack::Sendfile, ::Gitlab::Middleware::WorkhorseSetContentTypeFeature - # Use caching across all environments caching_config_hash = Gitlab::Redis::Cache.params caching_config_hash[:namespace] = Gitlab::Redis::Cache::CACHE_NAMESPACE diff --git a/lib/gitlab/middleware/workhorse_set_content_type_feature.rb b/lib/gitlab/middleware/workhorse_set_content_type_feature.rb deleted file mode 100644 index 8a721034aa6..00000000000 --- a/lib/gitlab/middleware/workhorse_set_content_type_feature.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# This middleware sets a header in the response if the feature -# workhorse_set_content_type is enabled. This way we can enable/disable -# the feature in Workhorse. -# This feature let Workhorse set the proper Content-Type and Content-Disposition -# headers, because it is the component that really process the files and -# blobs contents. -# When the header Gitlab-Workhorse-Detect-Content-Type is set, Workhorse -# will try to calculate the content headers -# https://dev.gitlab.org/gitlab/gitlab-workhorse/merge_requests/3 - -module Gitlab - module Middleware - class WorkhorseSetContentTypeFeature - def initialize(app) - @app = app - end - - def call(env) - status, headers, body = @app.call(env) - - if Feature.enabled?(:workhorse_set_content_type) && workhorse_send_file_request?(headers) - headers[Gitlab::Workhorse::DETECT_HEADER] = "true" - end - - [status, headers, body] - end - - private - - def workhorse_send_file_request?(headers) - headers.include?('X-Sendfile') - end - end - end -end diff --git a/spec/lib/gitlab/middleware/workhorse_set_content_type_feature_spec.rb b/spec/lib/gitlab/middleware/workhorse_set_content_type_feature_spec.rb deleted file mode 100644 index 63517514d18..00000000000 --- a/spec/lib/gitlab/middleware/workhorse_set_content_type_feature_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Middleware::WorkhorseSetContentTypeFeature do - let(:app) { double(:app) } - let(:middleware) { described_class.new(app) } - let(:env) { {} } - let(:response_headers) { {} } - - describe '#call' do - before do - expect(app).to receive(:call).and_return([200, response_headers, ""]) - end - - shared_examples 'feature workhorse_set_content_type' do - before do - stub_feature_flags(workhorse_set_content_type: flag_value) - end - - context 'enabled' do - let(:flag_value) { true } - - it "sets #{Gitlab::Workhorse::DETECT_HEADER} header" do - _, headers, _ = middleware.call(env) - - expect(headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" - end - end - - context 'disabled' do - let(:flag_value) { false } - - it "does not set #{Gitlab::Workhorse::DETECT_HEADER} header" do - _, headers, _ = middleware.call(env) - - expect(headers.keys).not_to include(Gitlab::Workhorse::DETECT_HEADER) - end - end - end - - context "when X-Sendfile header is present" do - let(:response_headers) { { "X-Sendfile" => "whatever" } } - - it_behaves_like "feature workhorse_set_content_type" - end - end -end |