Use only one header to send git blobs

This commit is contained in:
Jacob Vosmaer 2016-02-01 11:33:22 +01:00
parent 0197549d57
commit 02afa6793c
4 changed files with 25 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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

21
lib/gitlab/workhorse.rb Normal file
View file

@ -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