Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 50b8eef

Browse filesBrowse files
dhermeslukesneeringer
authored andcommitted
Adding GCCL header for HTTP APIs. (#3046)
1 parent 5961058 commit 50b8eef
Copy full SHA for 50b8eef

File tree

Expand file treeCollapse file tree

3 files changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+43
-0
lines changed
Open diff view settings
Collapse file

‎packages/google-cloud-vision/google/cloud/vision/__init__.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-vision/google/cloud/vision/__init__.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@
1414

1515
"""Google Cloud Vision API package."""
1616

17+
18+
from pkg_resources import get_distribution
19+
__version__ = get_distribution('google-cloud-vision').version
20+
1721
from google.cloud.vision.client import Client
Collapse file

‎packages/google-cloud-vision/google/cloud/vision/_http.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-vision/google/cloud/vision/_http.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414

1515
"""HTTP Client for interacting with the Google Cloud Vision API."""
1616

17+
1718
from google.cloud import _http
1819

20+
from google.cloud.vision import __version__
1921
from google.cloud.vision.annotations import Annotations
2022
from google.cloud.vision.feature import Feature
2123

2224

25+
_CLIENT_INFO = _http.CLIENT_INFO_TEMPLATE.format(__version__)
26+
27+
2328
class Connection(_http.JSONConnection):
2429
"""A connection to Google Cloud Vision via the JSON REST API.
2530
@@ -36,6 +41,10 @@ class Connection(_http.JSONConnection):
3641
API_URL_TEMPLATE = '{api_base_url}/{api_version}{path}'
3742
"""A template for the URL of a particular API call."""
3843

44+
_EXTRA_HEADERS = {
45+
_http.CLIENT_INFO_HEADER: _CLIENT_INFO,
46+
}
47+
3948

4049
class _HTTPVisionAPI(object):
4150
"""Vision API for interacting with the JSON/HTTP version of Vision
Collapse file

‎packages/google-cloud-vision/unit_tests/test__http.py‎

Copy file name to clipboardExpand all lines: packages/google-cloud-vision/unit_tests/test__http.py
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ def test_default_url(self):
3838
conn = self._make_one(client)
3939
self.assertEqual(conn._client, client)
4040

41+
def test_extra_headers(self):
42+
from google.cloud import _http as base_http
43+
from google.cloud.vision import _http as MUT
44+
45+
http = mock.Mock(spec=['request'])
46+
response = mock.Mock(status=200, spec=['status'])
47+
data = b'brent-spiner'
48+
http.request.return_value = response, data
49+
client = mock.Mock(_http=http, spec=['_http'])
50+
51+
conn = self._make_one(client)
52+
req_data = 'req-data-boring'
53+
result = conn.api_request(
54+
'GET', '/rainbow', data=req_data, expect_json=False)
55+
self.assertEqual(result, data)
56+
57+
expected_headers = {
58+
'Content-Length': str(len(req_data)),
59+
'Accept-Encoding': 'gzip',
60+
base_http.CLIENT_INFO_HEADER: MUT._CLIENT_INFO,
61+
'User-Agent': conn.USER_AGENT,
62+
}
63+
expected_uri = conn.build_api_url('/rainbow')
64+
http.request.assert_called_once_with(
65+
body=req_data,
66+
headers=expected_headers,
67+
method='GET',
68+
uri=expected_uri,
69+
)
70+
4171

4272
class Test_HTTPVisionAPI(unittest.TestCase):
4373
def _get_target_class(self):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.