fix: Remove duplicate clauses in X-Goog-Api-Client header

This commit is contained in:
Daniel Azuma 2019-11-11 15:03:28 -08:00 committed by GitHub
parent 7d61018813
commit ddd4ecea51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -131,6 +131,9 @@ module Google
.find_all { |k, v| k.downcase == 'x-goog-api-client' }
.map { |(a, b)| b }
.join(' ')
.split
.find_all { |s| s !~ %r{^gl-ruby/|^gdcl/} }
.join(' ')
xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{Google::Apis::VERSION}"
xgac = old_xgac.empty? ? xgac : "#{old_xgac} #{xgac}"
header.delete_if { |k, v| k.downcase == 'x-goog-api-client' }

View File

@ -57,6 +57,14 @@ RSpec.describe Google::Apis::Core::ApiCommand do
expect(command.header['X-Goog-Api-Client']).to eql "foo/1.2.3 bar/4.5.6 #{x_goog_api_client_value}"
expect(command.header['x-goog-api-client']).to be nil
end
it 'should override existing gl-ruby/ and gdcl/ clauses' do
command.header['x-goog-api-client'] = "gl-ruby/0.0 foo/1.2.3"
command.header['X-Goog-Api-Client'] = "bar/4.5.6 gdcl/0.0"
command.prepare!
expect(command.header['X-Goog-Api-Client']).to eql "foo/1.2.3 bar/4.5.6 #{x_goog_api_client_value}"
expect(command.header['x-goog-api-client']).to be nil
end
end
context('with a request body') do