Commit f8db6991 authored by Andy Soiron's avatar Andy Soiron

Merge branch 'sh-fix-sidekiq-admin-cng' into 'master'

Disable Sendfile interface for serving Sidekiq Web assets

See merge request gitlab-org/gitlab!70113
parents 97b7e052 ba8bd315
......@@ -2,6 +2,10 @@
app = Rails.application
# Disable Sendfile for Sidekiq Web assets since Workhorse won't
# always have access to these files.
app.config.middleware.insert_before(Rack::Sendfile, Gitlab::Middleware::SidekiqWebStatic)
if app.config.public_file_server.enabled
# The `ActionDispatch::Static` middleware intercepts requests for static files
# by checking if they exist in the `/public` directory.
......
# frozen_string_literal: true
# This module removes the X-Sendfile-Type header for /admin/sidekiq
# assets since Workhorse isn't always guaranteed to have the assets
# present on disk, such as when using Cloud Native GitLab
# containers. These assets are also small and served infrequently so it
# should be fine to do this.
module Gitlab
module Middleware
class SidekiqWebStatic
SIDEKIQ_REGEX = %r{\A/admin/sidekiq/}.freeze
def initialize(app)
@app = app
end
def call(env)
env.delete('HTTP_X_SENDFILE_TYPE') if env['PATH_INFO'] =~ SIDEKIQ_REGEX
@app.call(env)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Middleware::SidekiqWebStatic do
let(:app) { double(:app) }
let(:middleware) { described_class.new(app) }
let(:env) { {} }
describe '#call' do
before do
env['HTTP_X_SENDFILE_TYPE'] = 'X-Sendfile'
env['PATH_INFO'] = path
end
context 'with an /admin/sidekiq route' do
let(:path) { '/admin/sidekiq/javascripts/application.js'}
it 'deletes the HTTP_X_SENDFILE_TYPE header' do
expect(app).to receive(:call)
middleware.call(env)
expect(env['HTTP_X_SENDFILE_TYPE']).to be_nil
end
end
context 'with some static asset route' do
let(:path) { '/assets/test.png' }
it 'keeps the HTTP_X_SENDFILE_TYPE header' do
expect(app).to receive(:call)
middleware.call(env)
expect(env['HTTP_X_SENDFILE_TYPE']).to eq('X-Sendfile')
end
end
end
end
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