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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
9f57ae11
Commit
9f57ae11
authored
Jul 12, 2018
by
Kia Mei Somabes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set content-disposition header for single file download in repository
parent
50c12894
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
15 deletions
+13
-15
app/controllers/projects/raw_controller.rb
app/controllers/projects/raw_controller.rb
+1
-2
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+8
-8
app/helpers/workhorse_helper.rb
app/helpers/workhorse_helper.rb
+2
-2
app/views/projects/blob/_header.html.haml
app/views/projects/blob/_header.html.haml
+2
-3
No files found.
app/controllers/projects/raw_controller.rb
View file @
9f57ae11
...
...
@@ -10,7 +10,6 @@ class Projects::RawController < Projects::ApplicationController
def
show
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
if
@blob
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
...
...
@@ -19,7 +18,7 @@ class Projects::RawController < Projects::ApplicationController
if
@blob
.
stored_externally?
send_lfs_object
else
send_git_blob
@repository
,
@blob
send_git_blob
@repository
,
@blob
,
params
[
:inline
]
end
else
render_404
...
...
app/helpers/blob_helper.rb
View file @
9f57ae11
...
...
@@ -114,7 +114,7 @@ module BlobHelper
icon
(
"
#{
file_type_icon_class
(
'file'
,
mode
,
name
)
}
fw"
)
end
def
blob_raw_url
(
only_path:
false
)
def
blob_raw_url
(
only_path:
false
,
inline:
nil
)
if
@build
&&
@entry
raw_project_job_artifacts_url
(
@project
,
@build
,
path:
@entry
.
path
,
only_path:
only_path
)
elsif
@snippet
...
...
@@ -124,7 +124,7 @@ module BlobHelper
raw_snippet_url
(
@snippet
,
only_path:
only_path
)
end
elsif
@blob
project_raw_url
(
@project
,
@id
,
only_path:
only_path
)
project_raw_url
(
@project
,
@id
,
only_path:
only_path
,
inline:
inline
)
end
end
...
...
@@ -226,16 +226,16 @@ module BlobHelper
def
open_raw_blob_button
(
blob
)
return
if
blob
.
empty?
icon
=
icon
(
'file-code-o'
)
title
=
'Open raw'
link_to
icon
,
blob_raw_path
,
class:
'btn btn-sm has-tooltip'
,
target:
'_blank'
,
rel:
'noopener noreferrer'
,
title:
title
,
data:
{
container:
'body'
}
unless
blob
.
raw_binary?
||
blob
.
stored_externally?
title
=
'Open raw'
link_to
icon
(
'file-code-o'
),
blob_raw_url
(
:inline
=>
true
),
class:
'btn btn-sm has-tooltip'
,
target:
'_blank'
,
rel:
'noopener noreferrer'
,
title:
title
,
data:
{
container:
'body'
}
end
end
def
download_button
(
blob
)
def
download_b
lob_b
utton
(
blob
)
return
if
blob
.
empty?
icon
=
sprite_icon
(
'download'
)
title
=
'Download'
link_to
icon
,
blob_raw_path
,
download:
''
,
class:
'btn btn-sm has-tooltip'
,
target:
'_blank'
,
rel:
'noopener noreferrer'
,
title:
title
,
data:
{
container:
'body'
}
link_to
sprite_icon
(
'download'
),
blob_raw_url
,
download:
@path
,
class:
'btn btn-sm has-tooltip'
,
target:
'_blank'
,
rel:
'noopener noreferrer'
,
title:
title
,
data:
{
container:
'body'
}
end
def
blob_render_error_reason
(
viewer
)
...
...
app/helpers/workhorse_helper.rb
View file @
9f57ae11
...
...
@@ -2,9 +2,9 @@
# Workhorse will also serve files when using `send_file`.
module
WorkhorseHelper
# Send a Git blob through Workhorse
def
send_git_blob
(
repository
,
blob
)
def
send_git_blob
(
repository
,
blob
,
inline
)
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
repository
,
blob
))
headers
[
'Content-Disposition'
]
=
'inline'
inline
?
(
headers
[
'Content-Disposition'
]
=
'inline'
)
:
(
headers
[
'Content-Disposition'
]
=
'attachment'
)
headers
[
'Content-Type'
]
=
safe_content_type
(
blob
)
render
plain:
""
end
...
...
app/views/projects/blob/_header.html.haml
View file @
9f57ae11
...
...
@@ -7,9 +7,8 @@
.btn-group
{
role:
"group"
}
<
=
copy_blob_source_button
(
blob
)
unless
blame
-
if
!
(
blob
.
raw_binary?
||
blob
.
stored_externally?
)
=
open_raw_blob_button
(
blob
)
=
download_button
(
blob
)
=
open_raw_blob_button
(
blob
)
=
download_blob_button
(
blob
)
=
view_on_environment_button
(
@commit
.
sha
,
@path
,
@environment
)
if
@environment
.btn-group
{
role:
"group"
}
<
=
render_if_exists
'projects/blob/header_file_locks_link'
...
...
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