feat(core): Munge reported client version so backends can recognize split clients

This commit is contained in:
Daniel Azuma 2021-01-01 09:41:23 -08:00 committed by GitHub
parent 1e2aeaeeeb
commit abb3c968fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -60,7 +60,7 @@ module Google
# Request body # Request body
def initialize(method, url, body: nil, client_version: nil) def initialize(method, url, body: nil, client_version: nil)
super(method, url, body: body) super(method, url, body: body)
self.client_version = client_version || '0.0' self.client_version = client_version || Core::VERSION
end end
# Serialize the request body # Serialize the request body
@ -151,7 +151,14 @@ module Google
.split .split
.find_all { |s| s !~ %r{^gl-ruby/|^gdcl/} } .find_all { |s| s !~ %r{^gl-ruby/|^gdcl/} }
.join(' ') .join(' ')
xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{client_version}" # Report 0.x.y versions that are in separate packages as 1.x.y.
# Thus, reported gdcl/0.x.y versions are monopackage clients, while
# reported gdcl/1.x.y versions are split clients.
# In the unlikely event that we want to release post-1.0 versions of
# these clients, we should start the versioning at 2.0 to avoid
# confusion.
munged_client_version = client_version.sub(/^0\./, "1.")
xgac = "gl-ruby/#{RUBY_VERSION} gdcl/#{munged_client_version}"
xgac = old_xgac.empty? ? xgac : "#{old_xgac} #{xgac}" xgac = old_xgac.empty? ? xgac : "#{old_xgac} #{xgac}"
header.delete_if { |k, v| k.downcase == 'x-goog-api-client' } header.delete_if { |k, v| k.downcase == 'x-goog-api-client' }
header['X-Goog-Api-Client'] = xgac header['X-Goog-Api-Client'] = xgac