diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2017-04-07 16:47:28 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2017-04-10 11:45:37 +0300 |
commit | f8dd11957ace6897e0273babfc87a6d02348388c (patch) | |
tree | 7fb7b5efa14889b78a45e7c819ed047582f0e7a7 /lib/gitlab/etag_caching/router.rb | |
parent | c98add157732004d9a2eaa39770edf84eaca6896 (diff) |
Test all enabled routes in ETag caching middleware and fix pipeline routes
Extract route matching logic to Gitlab::EtagCaching::Router.
Fix pipeline routes:
1. "project_pipelines" has to come after "commit_pipelines" and
"merge_request_pipelines" because it is more generic
2. "commit_pipelines": "\s" (any whitespace character) => "\S"
(any non-whitespace character).
Diffstat (limited to 'lib/gitlab/etag_caching/router.rb')
-rw-r--r-- | lib/gitlab/etag_caching/router.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/gitlab/etag_caching/router.rb b/lib/gitlab/etag_caching/router.rb new file mode 100644 index 00000000000..f6e4f279c06 --- /dev/null +++ b/lib/gitlab/etag_caching/router.rb @@ -0,0 +1,39 @@ +module Gitlab + module EtagCaching + class Router + Route = Struct.new(:regexp, :name) + + RESERVED_WORDS = NamespaceValidator::WILDCARD_ROUTES.map { |word| "/#{word}/" }.join('|') + ROUTES = [ + Gitlab::EtagCaching::Router::Route.new( + %r(^(?!.*(#{RESERVED_WORDS})).*/noteable/issue/\d+/notes\z), + 'issue_notes' + ), + Gitlab::EtagCaching::Router::Route.new( + %r(^(?!.*(#{RESERVED_WORDS})).*/issues/\d+/rendered_title\z), + 'issue_title' + ), + Gitlab::EtagCaching::Router::Route.new( + %r(^(?!.*(#{RESERVED_WORDS})).*/commit/\S+/pipelines\.json\z), + 'commit_pipelines' + ), + Gitlab::EtagCaching::Router::Route.new( + %r(^(?!.*(#{RESERVED_WORDS})).*/merge_requests/new\.json\z), + 'new_merge_request_pipelines' + ), + Gitlab::EtagCaching::Router::Route.new( + %r(^(?!.*(#{RESERVED_WORDS})).*/merge_requests/\d+/pipelines\.json\z), + 'merge_request_pipelines' + ), + Gitlab::EtagCaching::Router::Route.new( + %r(^(?!.*(#{RESERVED_WORDS})).*/pipelines\.json\z), + 'project_pipelines' + ) + ].freeze + + def self.match(env) + ROUTES.find { |route| route.regexp.match(env['PATH_INFO']) } + end + end + end +end |