Commit 037fae65 authored by Robert Speicher's avatar Robert Speicher

Merge branch '10io-use-empty-string-when-sending-local-file' into 'master'

Use an empty body when sending a file with X-Sendfile

See merge request gitlab-org/gitlab!51115
parents db700dd3 d83cd4f0
---
title: Use an empty body when sending a file with X-Sendfile
merge_request: 51115
author:
type: fixed
...@@ -521,7 +521,7 @@ module API ...@@ -521,7 +521,7 @@ module API
case headers['X-Sendfile-Type'] case headers['X-Sendfile-Type']
when 'X-Sendfile' when 'X-Sendfile'
header['X-Sendfile'] = path header['X-Sendfile'] = path
body body '' # to avoid an error from API::APIGuard::ResponseCoercerMiddleware
else else
sendfile path sendfile path
end end
...@@ -537,7 +537,7 @@ module API ...@@ -537,7 +537,7 @@ module API
else else
header(*Gitlab::Workhorse.send_url(file.url)) header(*Gitlab::Workhorse.send_url(file.url))
status :ok status :ok
body "" body '' # to avoid an error from API::APIGuard::ResponseCoercerMiddleware
end end
end end
......
...@@ -363,4 +363,49 @@ RSpec.describe API::Helpers do ...@@ -363,4 +363,49 @@ RSpec.describe API::Helpers do
end end
end end
end end
describe '#present_disk_file!' do
let_it_be(:dummy_class) do
Class.new do
attr_reader :headers
alias_method :header, :headers
def initialize
@headers = {}
end
end
end
let(:dummy_instance) { dummy_class.include(described_class).new }
let(:path) { '/tmp/file.txt' }
let(:filename) { 'file.txt' }
subject { dummy_instance.present_disk_file!(path, filename) }
before do
expect(dummy_instance).to receive(:content_type).with('application/octet-stream')
end
context 'with X-Sendfile supported' do
before do
dummy_instance.headers['X-Sendfile-Type'] = 'X-Sendfile'
end
it 'sends the file using X-Sendfile' do
expect(dummy_instance).to receive(:body).with('')
subject
expect(dummy_instance.headers['X-Sendfile']).to eq(path)
end
end
context 'without X-Sendfile supported' do
it 'sends the file' do
expect(dummy_instance).to receive(:sendfile).with(path)
subject
end
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