Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Expire only for other users

Oliver Günther05ed8d2e6aaa
diff --git a/modules/avatars/lib/api/v3/users/user_avatar_api.rb b/modules/avatars/lib/api/v3/users/user_avatar_api.rb
index 481a9cc7cc8..d6bd80b02bd 100644
--- a/modules/avatars/lib/api/v3/users/user_avatar_api.rb
+++ b/modules/avatars/lib/api/v3/users/user_avatar_api.rb
@@ -34,11 +34,19 @@ module API
helpers ::AvatarHelper
helpers ::API::Helpers::AttachmentRenderer
+ helpers do
+ def set_cache_headers!
+ return if @user == current_user
+
+ # Cache for one day if not the current user
+ expire_in = 60 * 60 * 24
+ header "Cache-Control", "public, max-age=#{expire_in}"
+ header "Expires", CGI.rfc1123_date(Time.now.utc + expire_in)
+ end
+ end
+
get '/avatar' do
- # Cache for one day
- expire_in = 60 * 60 * 24
- header "Cache-Control", "public, max-age=#{expire_in}"
- header "Expires", CGI.rfc1123_date(Time.now.utc + expire_in)
+ set_cache_headers!
if local_avatar = local_avatar?(@user)
respond_with_attachment(local_avatar)