Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rails.rb « router « etag_caching « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5fd592c43e44bc8d7a2a51b32c5a60c543e9d727 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# frozen_string_literal: true

module Gitlab
  module EtagCaching
    module Router
      class Rails
        extend EtagCaching::Router::Helpers

        # 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
        #   - 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)))
        RESERVED_WORDS_PREFIX = %(^(?!.*\/(#{RESERVED_WORDS_REGEX})\/).*)

        ROUTES = [
          [
            %r(#{RESERVED_WORDS_PREFIX}/noteable/issue/\d+/notes\z),
            'issue_notes',
            ::Projects::NotesController,
            :index
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/noteable/merge_request/\d+/notes\z),
            'merge_request_notes',
            ::Projects::NotesController,
            :index
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/issues/\d+/realtime_changes\z),
            'issue_title',
            ::Projects::IssuesController,
            :realtime_changes
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/commit/\S+/pipelines\.json\z),
            'commit_pipelines',
            ::Projects::CommitController,
            :pipelines
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/merge_requests/new\.json\z),
            'new_merge_request_pipelines',
            ::Projects::MergeRequests::CreationsController,
            :new
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/merge_requests/\d+/pipelines\.json\z),
            'merge_request_pipelines',
            ::Projects::MergeRequestsController,
            :pipelines
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/pipelines\.json\z),
            'project_pipelines',
            ::Projects::PipelinesController,
            :index
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/pipelines/\d+\.json\z),
            'project_pipeline',
            ::Projects::PipelinesController,
            :show
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/builds/\d+\.json\z),
            'project_build',
            ::Projects::BuildsController,
            :show
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/clusters/\d+/environments\z),
            'cluster_environments',
            ::Groups::ClustersController,
            :environments
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/-/environments\.json\z),
            'environments',
            ::Projects::EnvironmentsController,
            :index
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/import/github/realtime_changes\.json\z),
            'realtime_changes_import_github',
            ::Import::GithubController,
            :realtime_changes
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/import/gitea/realtime_changes\.json\z),
            'realtime_changes_import_gitea',
            ::Import::GiteaController,
            :realtime_changes
          ],
          [
            %r(#{RESERVED_WORDS_PREFIX}/merge_requests/\d+/cached_widget\.json\z),
            'merge_request_widget',
            ::Projects::MergeRequests::ContentController,
            :cached_widget
          ]
        ].map { |attrs| build_rails_route(*attrs) }.freeze

        # Overridden in EE to add more routes
        def self.all_routes
          ROUTES
        end

        def self.match(request)
          all_routes.find { |route| route.match(request.path_info) }
        end

        def self.cache_key(request)
          request.path
        end
      end
    end
  end
end

Gitlab::EtagCaching::Router::Rails.prepend_mod_with('Gitlab::EtagCaching::Router::Rails')