summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-31 06:13:01 -0700
committerStan Hu <stanhu@gmail.com>2018-07-31 06:15:14 -0700
commitc5645a673955d5711bf589ad60ee6607220fdc9d (patch)
treeefb95d7ee78c7eb2ffb8abe8bbb71584e321a6d3
parente9d04585f872121d4b1f96e019946cfa48d2f915 (diff)
downloadgitlab-ce-c5645a673955d5711bf589ad60ee6607220fdc9d.tar.gz
Fix LFS uploads not working with git-lfs 2.5.0
git-lfs 2.5.0 now sets the Content-Type header instead of hard-coding it to application/octet-stream: https://github.com/git-lfs/git-lfs/pull/3137 To avoid this issue, we explicitly tell the client to use application/octet-stream. Closes #49752
-rw-r--r--app/controllers/projects/lfs_api_controller.rb7
-rw-r--r--changelogs/unreleased/sh-lfs-fix-content-type.yml5
-rw-r--r--spec/requests/lfs_http_spec.rb6
3 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/projects/lfs_api_controller.rb b/app/controllers/projects/lfs_api_controller.rb
index c64ccc3d473..a01351ba292 100644
--- a/app/controllers/projects/lfs_api_controller.rb
+++ b/app/controllers/projects/lfs_api_controller.rb
@@ -1,6 +1,8 @@
class Projects::LfsApiController < Projects::GitHttpClientController
include LfsRequest
+ LFS_TRANSFER_CONTENT_TYPE = 'application/octet-stream'.freeze
+
skip_before_action :lfs_check_access!, only: [:deprecated]
before_action :lfs_check_batch_operation!, only: [:batch]
@@ -86,7 +88,10 @@ class Projects::LfsApiController < Projects::GitHttpClientController
upload: {
href: "#{project.http_url_to_repo}/gitlab-lfs/objects/#{object[:oid]}/#{object[:size]}",
header: {
- Authorization: request.headers['Authorization']
+ Authorization: request.headers['Authorization'],
+ # git-lfs v2.5.0 sets the Content-Type based on the uploaded file. This
+ # ensures that Workhorse can intercept the request.
+ 'Content-Type': LFS_TRANSFER_CONTENT_TYPE
}.compact
}
}
diff --git a/changelogs/unreleased/sh-lfs-fix-content-type.yml b/changelogs/unreleased/sh-lfs-fix-content-type.yml
new file mode 100644
index 00000000000..a839be9b3ae
--- /dev/null
+++ b/changelogs/unreleased/sh-lfs-fix-content-type.yml
@@ -0,0 +1,5 @@
+---
+title: Fix LFS uploads not working with git-lfs 2.5.0
+merge_request: 20923
+author:
+type: fixed
diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb
index c2378646f89..e349181b794 100644
--- a/spec/requests/lfs_http_spec.rb
+++ b/spec/requests/lfs_http_spec.rb
@@ -732,7 +732,7 @@ describe 'Git LFS API and storage' do
expect(json_response['objects'].first['oid']).to eq(sample_oid)
expect(json_response['objects'].first['size']).to eq(sample_size)
expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}")
- expect(json_response['objects'].first['actions']['upload']['header']).to eq('Authorization' => authorization)
+ expect(json_response['objects'].first['actions']['upload']['header']).to eq({ 'Authorization' => authorization, 'Content-Type' => 'application/octet-stream' })
end
end
@@ -761,7 +761,7 @@ describe 'Git LFS API and storage' do
expect(lfs_object.projects.pluck(:id)).not_to include(project.id)
expect(lfs_object.projects.pluck(:id)).to include(other_project.id)
expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}")
- expect(json_response['objects'].first['actions']['upload']['header']).to eq('Authorization' => authorization)
+ expect(json_response['objects'].first['actions']['upload']['header']).to eq({ 'Authorization' => authorization, 'Content-Type' => 'application/octet-stream' })
end
end
@@ -796,7 +796,7 @@ describe 'Git LFS API and storage' do
expect(json_response['objects'].first['oid']).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897")
expect(json_response['objects'].first['size']).to eq(1575078)
expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078")
- expect(json_response['objects'].first['actions']['upload']['header']).to eq("Authorization" => authorization)
+ expect(json_response['objects'].first['actions']['upload']['header']).to eq({ 'Authorization' => authorization, 'Content-Type' => 'application/octet-stream' })
expect(json_response['objects'].last['oid']).to eq(sample_oid)
expect(json_response['objects'].last['size']).to eq(sample_size)