Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

git_http.rb 1.99 KB
Newer Older
1
2
scope(path: '*namespace_id/:project_id',
      format: nil,
3
4
      constraints: { namespace_id: Gitlab::PathRegex.full_namespace_route_regex }) do
  scope(constraints: { project_id: Gitlab::PathRegex.project_git_route_regex }, module: :projects) do
5
6
7
8
9
10
    # Git HTTP clients ('git clone' etc.)
    scope(controller: :git_http) do
      get '/info/refs', action: :info_refs
      post '/git-upload-pack', action: :git_upload_pack
      post '/git-receive-pack', action: :git_receive_pack
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
11

12
13
14
15
16
17
    # Git LFS API (metadata)
    scope(path: 'info/lfs/objects', controller: :lfs_api) do
      post :batch
      post '/', action: :deprecated
      get '/*oid', action: :deprecated
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
18

19
20
21
22
23
24
25
    scope(path: 'info/lfs') do
      resources :lfs_locks, controller: :lfs_locks_api, path: 'locks' do
        post :unlock, on: :member
        post :verify, on: :collection
      end
    end

26
27
28
    # GitLab LFS object storage
    scope(path: 'gitlab-lfs/objects/*oid', controller: :lfs_storage, constraints: { oid: /[a-f0-9]{64}/ }) do
      get '/', action: :download
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
29

30
31
32
33
      scope constraints: { size: /[0-9]+/ } do
        put '/*size/authorize', action: :upload_authorize
        put '/*size', action: :upload_finalize
      end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
34
35
36
    end
  end

37
  # Redirect /group/project/info/refs to /group/project.git/info/refs
38
  scope(constraints: { project_id: Gitlab::PathRegex.project_route_regex }) do
39
40
41
42
43
44
45
46
    # Allow /info/refs, /info/refs?service=git-upload-pack, and
    # /info/refs?service=git-receive-pack, but nothing else.
    #
    git_http_handshake = lambda do |request|
      ProjectUrlConstrainer.new.matches?(request) &&
        (request.query_string.blank? ||
         request.query_string.match(/\Aservice=git-(upload|receive)-pack\z/))
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
47

48
49
50
51
52
    ref_redirect = redirect do |params, request|
      path = "#{params[:namespace_id]}/#{params[:project_id]}.git/info/refs"
      path << "?#{request.query_string}" unless request.query_string.blank?
      path
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
53

54
55
56
    get '/info/refs', constraints: git_http_handshake, to: ref_redirect
  end
end