Commit 9daf290d authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '254281-add-user-agent-to-git-lfs-client' into 'master'

Fix verifying uploads with GitHub

See merge request gitlab-org/gitlab!43852
parents 3d6c0f6e ce8fc586
---
title: Fix verifying LFS uploads with GitHub
merge_request: 43852
author:
type: fixed
......@@ -7,9 +7,11 @@ module Gitlab
# * https://github.com/git-lfs/git-lfs/blob/master/docs/api/basic-transfers.md
class Client
GIT_LFS_CONTENT_TYPE = 'application/vnd.git-lfs+json'
GIT_LFS_USER_AGENT = "GitLab #{Gitlab::VERSION} LFS client"
DEFAULT_HEADERS = {
'Accept' => GIT_LFS_CONTENT_TYPE,
'Content-Type' => GIT_LFS_CONTENT_TYPE
'Content-Type' => GIT_LFS_CONTENT_TYPE,
'User-Agent' => GIT_LFS_USER_AGENT
}.freeze
attr_reader :base_url
......@@ -53,7 +55,8 @@ module Gitlab
body_stream: file,
headers: {
'Content-Length' => object.size.to_s,
'Content-Type' => 'application/octet-stream'
'Content-Type' => 'application/octet-stream',
'User-Agent' => GIT_LFS_USER_AGENT
}.merge(upload_action['header'] || {})
}
......
......@@ -8,6 +8,7 @@ RSpec.describe Gitlab::Lfs::Client do
let(:password) { 'password' }
let(:credentials) { { user: username, password: password, auth_method: 'password' } }
let(:git_lfs_content_type) { 'application/vnd.git-lfs+json' }
let(:git_lfs_user_agent) { "GitLab #{Gitlab::VERSION} LFS client" }
let(:basic_auth_headers) do
{ 'Authorization' => "Basic #{Base64.strict_encode64("#{username}:#{password}")}" }
......@@ -91,7 +92,8 @@ RSpec.describe Gitlab::Lfs::Client do
headers = {
'Accept' => git_lfs_content_type,
'Content-Type' => git_lfs_content_type
'Content-Type' => git_lfs_content_type,
'User-Agent' => git_lfs_user_agent
}.merge(headers)
stub_request(:post, base_url + '/info/lfs/objects/batch').with(body: body, headers: headers)
......@@ -156,7 +158,8 @@ RSpec.describe Gitlab::Lfs::Client do
def stub_upload(object:, headers:)
headers = {
'Content-Type' => 'application/octet-stream',
'Content-Length' => object.size.to_s
'Content-Length' => object.size.to_s,
'User-Agent' => git_lfs_user_agent
}.merge(headers)
stub_request(:put, upload_action['href']).with(
......@@ -209,7 +212,8 @@ RSpec.describe Gitlab::Lfs::Client do
def stub_verify(object:, headers:)
headers = {
'Accept' => git_lfs_content_type,
'Content-Type' => git_lfs_content_type
'Content-Type' => git_lfs_content_type,
'User-Agent' => git_lfs_user_agent
}.merge(headers)
stub_request(:post, verify_action['href']).with(
......
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