Commit 02afa679 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use only one header to send git blobs

parent 0197549d
...@@ -6,8 +6,7 @@ class Projects::AvatarsController < Projects::ApplicationController ...@@ -6,8 +6,7 @@ class Projects::AvatarsController < Projects::ApplicationController
@blob = repository.blob_at_branch('master', @project.avatar_in_git) @blob = repository.blob_at_branch('master', @project.avatar_in_git)
if @blob if @blob
headers['X-Content-Type-Options'] = 'nosniff' headers['X-Content-Type-Options'] = 'nosniff'
headers['Gitlab-Workhorse-Repo-Path'] = repository.path_to_repo headers.store(*Gitlab::Workhorse.send_git_blob(repository, @blob))
headers['Gitlab-Workhorse-Send-Blob'] = @blob.id
headers['Content-Disposition'] = 'inline' headers['Content-Disposition'] = 'inline'
render nothing: true, content_type: @blob.content_type render nothing: true, content_type: @blob.content_type
else else
......
...@@ -15,8 +15,7 @@ class Projects::RawController < Projects::ApplicationController ...@@ -15,8 +15,7 @@ class Projects::RawController < Projects::ApplicationController
if @blob.lfs_pointer? if @blob.lfs_pointer?
send_lfs_object send_lfs_object
else else
headers['Gitlab-Workhorse-Repo-Path'] = @repository.path_to_repo headers.store(*Gitlab::Workhorse.send_git_blob(@repository, @blob))
headers['Gitlab-Workhorse-Send-Blob'] = @blob.id
headers['Content-Disposition'] = 'inline' headers['Content-Disposition'] = 'inline'
render nothing: true, content_type: get_blob_type render nothing: true, content_type: get_blob_type
end end
......
...@@ -57,8 +57,7 @@ module API ...@@ -57,8 +57,7 @@ module API
not_found! "File" unless blob not_found! "File" unless blob
content_type 'text/plain' content_type 'text/plain'
header 'Gitlab-Workhorse-Repo-Path', repo.path_to_repo header *Gitlab::Workhorse.send_git_blob(repo, blob)
header 'Gitlab-Workhorse-Send-Blob', blob.id
end end
# Get a raw blob contents by blob sha # Get a raw blob contents by blob sha
...@@ -84,8 +83,7 @@ module API ...@@ -84,8 +83,7 @@ module API
env['api.format'] = :txt env['api.format'] = :txt
content_type blob.mime_type content_type blob.mime_type
header 'Gitlab-Workhorse-Repo-Path', repo.path_to_repo header *Gitlab::Workhorse.send_git_blob(repo, blob)
header 'Gitlab-Workhorse-Send-Blob', blob.id
end end
# Get a an archive of the repository # Get a an archive of the repository
......
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment