Skip to content

Commit 66d643d

Browse files
committed
Add python version and platform to user agent header
1 parent 090c5d1 commit 66d643d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

openeo/rest/connection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import logging
66
import pathlib
77
import shutil
8+
import sys
89
import warnings
910
from typing import Dict, List
1011
from urllib.parse import urljoin
@@ -55,7 +56,11 @@ def __init__(self, root_url: str, auth: AuthBase = None, session: requests.Sessi
5556
self.session = session or requests.Session()
5657
self.auth = auth or NullAuth()
5758
self.default_headers = {
58-
"User-Agent": "openeo-python-client/{v}".format(v=openeo.client_version())
59+
"User-Agent": "openeo-python-client/{cv} {py}/{pv} {pl}".format(
60+
cv=openeo.client_version(),
61+
py=sys.implementation.name, pv=".".join(map(str,sys.version_info[:3])),
62+
pl=sys.platform
63+
)
5964
}
6065

6166
def build_url(self, path: str):

tests/rest/test_connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import re
12
import unittest.mock as mock
23

34
import pytest
45
import requests_mock
5-
from openeo.rest import OpenEoClientException
66

7+
from openeo.rest import OpenEoClientException
78
from openeo.rest.auth.auth import NullAuth, BearerAuth
89
from openeo.rest.connection import Connection, RestApiConnection, connect, OpenEoApiError
910

@@ -40,7 +41,11 @@ def test_rest_api_headers():
4041
conn = RestApiConnection(API_URL)
4142
with requests_mock.Mocker() as m:
4243
def text(request, context):
43-
assert request.headers["User-Agent"].startswith("openeo-python-client")
44+
assert re.match(
45+
r"^openeo-python-client/[0-9a-z.-]+ .*python/3.* (linux|win|darwin)",
46+
request.headers["User-Agent"],
47+
re.I
48+
)
4449
assert request.headers["X-Openeo-Bar"] == "XY123"
4550

4651
m.get("/foo", text=text)

0 commit comments

Comments
 (0)