Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d83cd4f0
Commit
d83cd4f0
authored
Jan 11, 2021
by
David Fernandez
Committed by
Robert Speicher
Jan 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use an empty body when sending a file with X-Sendfile
See
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/45340
parent
9dc7d230
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
2 deletions
+52
-2
changelogs/unreleased/10io-use-empty-string-when-sending-local-file.yml
...eleased/10io-use-empty-string-when-sending-local-file.yml
+5
-0
lib/api/helpers.rb
lib/api/helpers.rb
+2
-2
spec/lib/api/helpers_spec.rb
spec/lib/api/helpers_spec.rb
+45
-0
No files found.
changelogs/unreleased/10io-use-empty-string-when-sending-local-file.yml
0 → 100644
View file @
d83cd4f0
---
title
:
Use an empty body when sending a file with X-Sendfile
merge_request
:
51115
author
:
type
:
fixed
lib/api/helpers.rb
View file @
d83cd4f0
...
...
@@ -521,7 +521,7 @@ module API
case
headers
[
'X-Sendfile-Type'
]
when
'X-Sendfile'
header
[
'X-Sendfile'
]
=
path
body
body
''
# to avoid an error from API::APIGuard::ResponseCoercerMiddleware
else
sendfile
path
end
...
...
@@ -537,7 +537,7 @@ module API
else
header
(
*
Gitlab
::
Workhorse
.
send_url
(
file
.
url
))
status
:ok
body
""
body
''
# to avoid an error from API::APIGuard::ResponseCoercerMiddleware
end
end
...
...
spec/lib/api/helpers_spec.rb
View file @
d83cd4f0
...
...
@@ -363,4 +363,49 @@ RSpec.describe API::Helpers do
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment