Skip to content

Commit

Permalink
feat: Add x-goog-api-client header to rest clients (#888)
Browse files Browse the repository at this point in the history
Also make api-core 1.27.0 minimum requirement
  • Loading branch information
vam-google committed May 20, 2021
1 parent 81932a2 commit 2d1d3ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Expand Up @@ -6,6 +6,9 @@ import abc
from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
import packaging.version
import pkg_resources
{% if 'rest' in opts.transport %}
from requests import __version__ as requests_version
{% endif %}

import google.auth # type: ignore
import google.api_core # type: ignore
Expand Down Expand Up @@ -33,6 +36,12 @@ try:
gapic_version=pkg_resources.get_distribution(
'{{ api.naming.warehouse_package_name }}',
).version,
{% if 'grpc' not in opts.transport %}
grpc_version=None,
{% endif %}
{% if 'rest' in opts.transport %}
rest_version=requests_version,
{% endif %}
)
except pkg_resources.DistributionNotFound:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
Expand Down
Expand Up @@ -208,8 +208,11 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
url += '?{}'.format('&'.join(query_params)).replace(' ', '+')

# Send the request
headers = dict(metadata)
headers['Content-Type'] = 'application/json'
response = self._session.{{ method.http_opt['verb'] }}(
url,
headers=headers,
{% if 'body' in method.http_opt %}
data=body,
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion gapic/templates/setup.py.j2
Expand Up @@ -27,7 +27,7 @@ setuptools.setup(
platforms='Posix; MacOS X; Windows',
include_package_data=True,
install_requires=(
'google-api-core[grpc] >= 1.26.0, < 2.0.0dev',
'google-api-core[grpc] >= 1.27.0, < 2.0.0dev',
'libcst >= 0.2.5',
'proto-plus >= 1.15.0',
'packaging >= 14.3',
Expand Down

0 comments on commit 2d1d3ae

Please sign in to comment.