summaryrefslogtreecommitdiff
path: root/lib/gitlab/etag_caching/router.rb
blob: 15ae24f62c8c1f302e2878397205e2f23a25459f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
<<<<<<< HEAD
      #   - Ending in `issues/id`/rendered_title` for the `issue_title` route
<<<<<<< HEAD
=======
      #   - Ending in `issues/id`/realtime_changes` for the `issue_title` route
>>>>>>> 2f62af6... Restore original comment [ci skip]
      USED_IN_ROUTES = %w[noteable issue notes issues realtime_changes
<<<<<<< HEAD
<<<<<<< HEAD
                          commit pipelines merge_requests new].freeze
=======
                          commit pipelines merge_requests builds
                          new].freeze

>>>>>>> 47a0276... Initial implementation for real time job view
      RESERVED_WORDS = Gitlab::PathRegex::ILLEGAL_PROJECT_PATH_WORDS - USED_IN_ROUTES
      RESERVED_WORDS_REGEX = Regexp.union(*RESERVED_WORDS.map(&Regexp.method(:escape)))
=======
=======
      USED_IN_ROUTES = %w[noteable issue notes issues rendered_title
>>>>>>> 4535d52... Use etag caching for environments JSON
                          commit pipelines merge_requests new
                          environments].freeze
      RESERVED_WORDS = DynamicPathValidator::WILDCARD_ROUTES - USED_IN_ROUTES
      RESERVED_WORDS_REGEX = Regexp.union(*RESERVED_WORDS)
>>>>>>> ebede2b... Use etag caching for environments JSON
      ROUTES = [
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/noteable/issue/\d+/notes\z),
          'issue_notes'
        ),
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/issues/\d+/realtime_changes\z),
          'issue_title'
        ),
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/commit/\S+/pipelines\.json\z),
          'commit_pipelines'
        ),
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/merge_requests/new\.json\z),
          'new_merge_request_pipelines'
        ),
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/merge_requests/\d+/pipelines\.json\z),
          'merge_request_pipelines'
        ),
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/pipelines\.json\z),
          'project_pipelines'
        ),
        Gitlab::EtagCaching::Router::Route.new(
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/pipelines/\d+\.json\z),
          'project_pipeline'
        ),
        Gitlab::EtagCaching::Router::Route.new(
<<<<<<< HEAD
<<<<<<< HEAD
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/environments\.json\z),
=======
          %r(^(?!.*(#{RESERVED_WORDS})).*/environments\.json\z),
>>>>>>> 4535d52... Use etag caching for environments JSON
          'environments'
=======
          %r(^(?!.*(#{RESERVED_WORDS_REGEX})).*/builds/\d+\.json\z),
          'project_build'
>>>>>>> 47a0276... Initial implementation for real time job view
        )
      ].freeze

      def self.match(env)
        ROUTES.find { |route| route.regexp.match(env['PATH_INFO']) }
      end
    end
  end
end