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
Jérome Perrin
gitlab-ce
Commits
fc90d9e5
Commit
fc90d9e5
authored
Mar 03, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tell clients/proxies to cache raw blob requests
parent
00cb4a97
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
4 deletions
+34
-4
app/controllers/projects/avatars_controller.rb
app/controllers/projects/avatars_controller.rb
+2
-0
app/controllers/projects/raw_controller.rb
app/controllers/projects/raw_controller.rb
+2
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+25
-0
app/models/project.rb
app/models/project.rb
+4
-3
app/views/projects/blob/_image.html.haml
app/views/projects/blob/_image.html.haml
+1
-1
No files found.
app/controllers/projects/avatars_controller.rb
View file @
fc90d9e5
...
@@ -7,6 +7,8 @@ class Projects::AvatarsController < Projects::ApplicationController
...
@@ -7,6 +7,8 @@ class Projects::AvatarsController < Projects::ApplicationController
@blob
=
@repository
.
blob_at_branch
(
'master'
,
@project
.
avatar_in_git
)
@blob
=
@repository
.
blob_at_branch
(
'master'
,
@project
.
avatar_in_git
)
if
@blob
if
@blob
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
set_cache_headers
check_etag!
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
@repository
,
@blob
))
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
@repository
,
@blob
))
headers
[
'Content-Disposition'
]
=
'inline'
headers
[
'Content-Disposition'
]
=
'inline'
headers
[
'Content-Type'
]
=
safe_content_type
(
@blob
)
headers
[
'Content-Type'
]
=
safe_content_type
(
@blob
)
...
...
app/controllers/projects/raw_controller.rb
View file @
fc90d9e5
...
@@ -12,6 +12,8 @@ class Projects::RawController < Projects::ApplicationController
...
@@ -12,6 +12,8 @@ class Projects::RawController < Projects::ApplicationController
if
@blob
if
@blob
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
headers
[
'X-Content-Type-Options'
]
=
'nosniff'
check_etag!
set_cache_headers
if
@blob
.
lfs_pointer?
if
@blob
.
lfs_pointer?
send_lfs_object
send_lfs_object
...
...
app/helpers/blob_helper.rb
View file @
fc90d9e5
...
@@ -152,4 +152,29 @@ module BlobHelper
...
@@ -152,4 +152,29 @@ module BlobHelper
'application/octet-stream'
'application/octet-stream'
end
end
end
end
def
set_cache_headers
if
@project
.
visibility_level
==
Project
::
PUBLIC
cache_control
=
'public, '
else
cache_control
=
'private, '
end
if
@ref
&&
@commit
&&
@ref
==
@commit
.
id
# This is a link to a commit by its commit SHA. That means that the blob
# is immutable.
cache_control
<<
'max-age=600'
# 10 minutes
else
# A branch or tag points at this blob. That means that the expected blob
# value may change over time.
cache_control
<<
'max-age=60'
# 1 minute
end
headers
[
'Cache-Control'
]
=
cache_control
headers
[
'ETag'
]
=
@blob
.
id
end
def
check_etag!
stale?
(
etag:
@blob
.
id
)
end
end
end
app/models/project.rb
View file @
fc90d9e5
...
@@ -56,6 +56,7 @@ class Project < ActiveRecord::Base
...
@@ -56,6 +56,7 @@ class Project < ActiveRecord::Base
extend
Gitlab
::
ConfigHelper
extend
Gitlab
::
ConfigHelper
UNKNOWN_IMPORT_URL
=
'http://unknown.git'
UNKNOWN_IMPORT_URL
=
'http://unknown.git'
AVATAR_BRANCH
=
'master'
default_value_for
:archived
,
false
default_value_for
:archived
,
false
default_value_for
:visibility_level
,
gitlab_config_features
.
visibility_level
default_value_for
:visibility_level
,
gitlab_config_features
.
visibility_level
...
@@ -544,9 +545,9 @@ class Project < ActiveRecord::Base
...
@@ -544,9 +545,9 @@ class Project < ActiveRecord::Base
end
end
def
avatar_in_git
def
avatar_in_git
@avatar_file
||=
'logo.png'
if
repository
.
blob_at_branch
(
'master'
,
'logo.png'
)
@avatar_file
||=
'logo.png'
if
repository
.
blob_at_branch
(
AVATAR_BRANCH
,
'logo.png'
)
@avatar_file
||=
'logo.jpg'
if
repository
.
blob_at_branch
(
'master'
,
'logo.jpg'
)
@avatar_file
||=
'logo.jpg'
if
repository
.
blob_at_branch
(
AVATAR_BRANCH
,
'logo.jpg'
)
@avatar_file
||=
'logo.gif'
if
repository
.
blob_at_branch
(
'master'
,
'logo.gif'
)
@avatar_file
||=
'logo.gif'
if
repository
.
blob_at_branch
(
AVATAR_BRANCH
,
'logo.gif'
)
@avatar_file
@avatar_file
end
end
...
...
app/views/projects/blob/_image.html.haml
View file @
fc90d9e5
...
@@ -6,4 +6,4 @@
...
@@ -6,4 +6,4 @@
-
blob
=
sanitize_svg
(
blob
)
-
blob
=
sanitize_svg
(
blob
)
%img
{
src:
"data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}"
}
%img
{
src:
"data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}"
}
-
else
-
else
%img
{
src:
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
)}
%img
{
src:
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
tree_join
(
@commit
.
id
,
blob
.
path
)
)}
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