debian-mirror-gitlab/lib/gitlab/etag_caching/router.rb

87 lines
3.3 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module EtagCaching
class Router
Route = Struct.new(:regexp, :name)
# We enable an ETag for every request matching the regex.
# To match a regex the path needs to match the following:
# - Don't contain a reserved word (expect for the words used in the
# regex itself)
# - Ending in `noteable/issue/<id>/notes` for the `issue_notes` route
2017-09-10 17:25:29 +05:30
# - Ending in `issues/id`/realtime_changes` for the `issue_title` route
USED_IN_ROUTES = %w[noteable issue notes issues realtime_changes
commit pipelines merge_requests builds
new environments].freeze
RESERVED_WORDS = Gitlab::PathRegex::ILLEGAL_PROJECT_PATH_WORDS - USED_IN_ROUTES
RESERVED_WORDS_REGEX = Regexp.union(*RESERVED_WORDS.map(&Regexp.method(:escape)))
2019-07-07 11:18:12 +05:30
RESERVED_WORDS_PREFIX = %Q(^(?!.*\/(#{RESERVED_WORDS_REGEX})\/).*)
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
ROUTES = [
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/noteable/issue/\d+/notes\z),
2017-08-17 22:00:37 +05:30
'issue_notes'
),
2020-01-01 13:55:28 +05:30
Gitlab::EtagCaching::Router::Route.new(
%r(#{RESERVED_WORDS_PREFIX}/noteable/merge_request/\d+/notes\z),
'merge_request_notes'
),
2017-08-17 22:00:37 +05:30
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/issues/\d+/realtime_changes\z),
2017-08-17 22:00:37 +05:30
'issue_title'
),
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/commit/\S+/pipelines\.json\z),
2017-08-17 22:00:37 +05:30
'commit_pipelines'
),
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/merge_requests/new\.json\z),
2017-08-17 22:00:37 +05:30
'new_merge_request_pipelines'
),
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/merge_requests/\d+/pipelines\.json\z),
2017-08-17 22:00:37 +05:30
'merge_request_pipelines'
),
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/pipelines\.json\z),
2017-08-17 22:00:37 +05:30
'project_pipelines'
),
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/pipelines/\d+\.json\z),
2017-08-17 22:00:37 +05:30
'project_pipeline'
),
2017-09-10 17:25:29 +05:30
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/builds/\d+\.json\z),
2017-09-10 17:25:29 +05:30
'project_build'
),
2019-12-04 20:38:33 +05:30
Gitlab::EtagCaching::Router::Route.new(
%r(#{RESERVED_WORDS_PREFIX}/clusters/\d+/environments\z),
'cluster_environments'
),
2017-09-10 17:25:29 +05:30
Gitlab::EtagCaching::Router::Route.new(
2019-07-07 11:18:12 +05:30
%r(#{RESERVED_WORDS_PREFIX}/environments\.json\z),
2017-09-10 17:25:29 +05:30
'environments'
2019-07-07 11:18:12 +05:30
),
Gitlab::EtagCaching::Router::Route.new(
%r(#{RESERVED_WORDS_PREFIX}/import/github/realtime_changes\.json\z),
'realtime_changes_import_github'
),
Gitlab::EtagCaching::Router::Route.new(
%r(#{RESERVED_WORDS_PREFIX}/import/gitea/realtime_changes\.json\z),
'realtime_changes_import_gitea'
2019-10-12 21:52:04 +05:30
),
Gitlab::EtagCaching::Router::Route.new(
%r(#{RESERVED_WORDS_PREFIX}/merge_requests/\d+/cached_widget\.json\z),
'merge_request_widget'
2017-09-10 17:25:29 +05:30
)
2017-08-17 22:00:37 +05:30
].freeze
2017-09-10 17:25:29 +05:30
def self.match(path)
ROUTES.find { |route| route.regexp.match(path) }
2017-08-17 22:00:37 +05:30
end
end
end
end
2019-12-26 22:10:19 +05:30
Gitlab::EtagCaching::Router.prepend_if_ee('EE::Gitlab::EtagCaching::Router')