diff options
author | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-02-01 13:33:22 +0300 |
---|---|---|
committer | Jacob Vosmaer <contact@jacobvosmaer.nl> | 2016-02-01 13:33:22 +0300 |
commit | 02afa6793cca042f8563b0e26472606c743d76f5 (patch) | |
tree | c2242a77660c2f07fefe3b0879b17a4e743bee53 | |
parent | 0197549d57bd32ee933ee775c625ed6fc5f5eec8 (diff) |
Use only one header to send git blobs
-rw-r--r-- | app/controllers/projects/avatars_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/projects/raw_controller.rb | 3 | ||||
-rw-r--r-- | lib/api/repositories.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/workhorse.rb | 21 |
4 files changed, 25 insertions, 8 deletions
diff --git a/app/controllers/projects/avatars_controller.rb b/app/controllers/projects/avatars_controller.rb index 0cd65ad5b16..eb501c3964c 100644 --- a/app/controllers/projects/avatars_controller.rb +++ b/app/controllers/projects/avatars_controller.rb @@ -6,8 +6,7 @@ class Projects::AvatarsController < Projects::ApplicationController @blob = repository.blob_at_branch('master', @project.avatar_in_git) if @blob headers['X-Content-Type-Options'] = 'nosniff' - headers['Gitlab-Workhorse-Repo-Path'] = repository.path_to_repo - headers['Gitlab-Workhorse-Send-Blob'] = @blob.id + headers.store(*Gitlab::Workhorse.send_git_blob(repository, @blob)) headers['Content-Disposition'] = 'inline' render nothing: true, content_type: @blob.content_type else diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb index b8b90489027..2ab8a6b83bb 100644 --- a/app/controllers/projects/raw_controller.rb +++ b/app/controllers/projects/raw_controller.rb @@ -15,8 +15,7 @@ class Projects::RawController < Projects::ApplicationController if @blob.lfs_pointer? send_lfs_object else - headers['Gitlab-Workhorse-Repo-Path'] = @repository.path_to_repo - headers['Gitlab-Workhorse-Send-Blob'] = @blob.id + headers.store(*Gitlab::Workhorse.send_git_blob(@repository, @blob)) headers['Content-Disposition'] = 'inline' render nothing: true, content_type: get_blob_type end diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 0f4cd2443b0..c95d2d2001d 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -57,8 +57,7 @@ module API not_found! "File" unless blob content_type 'text/plain' - header 'Gitlab-Workhorse-Repo-Path', repo.path_to_repo - header 'Gitlab-Workhorse-Send-Blob', blob.id + header *Gitlab::Workhorse.send_git_blob(repo, blob) end # Get a raw blob contents by blob sha @@ -84,8 +83,7 @@ module API env['api.format'] = :txt content_type blob.mime_type - header 'Gitlab-Workhorse-Repo-Path', repo.path_to_repo - header 'Gitlab-Workhorse-Send-Blob', blob.id + header *Gitlab::Workhorse.send_git_blob(repo, blob) end # Get a an archive of the repository diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb new file mode 100644 index 00000000000..ff6fbf0b5c1 --- /dev/null +++ b/lib/gitlab/workhorse.rb @@ -0,0 +1,21 @@ +require 'base64' +require 'json' + +module Gitlab + class Workhorse + class << self + def send_git_blob(repository, blob) + params_hash = { + 'RepoPath' => repository.path_to_repo, + 'BlobId' => blob.id, + } + params = Base64.urlsafe_encode64(JSON.dump(params_hash)) + + [ + 'Gitlab-Workhorse-Send-Data', + "git-blob:#{params}", + ] + end + end + end +end
\ No newline at end of file |