Skip to content

Commit 36ed4af

Browse files
authored
add X-Client-Version header to rest client (#2910)
Closes #2373 # Rationale for this change Bringing parity to the headers in Python. The version is as per the [HttpClient in Java](https://github.com/apache/iceberg/blob/68e555b94f4706a2af41dcb561c84007230c0bc1/core/src/main/java/org/apache/iceberg/rest/HTTPClient.java#L533-L534) and the version string is matching [IcebergBuild](https://github.com/apache/iceberg/blob/779af12312fcf70c1e6e52d610d64cf947fd0a4f/api/src/main/java/org/apache/iceberg/IcebergBuild.java#L67) but with `PyIceberg` instead of Iceberg. Previously, this was worked on #2652 but since that has stalled, adding a fix to close our the issue. Thanks to @jaimeferj for his original PR. ## Are these changes tested? - Added a test in `tests/catalog/test_rest.py` - `test_client_version_header` ## Are there any user-facing changes? No
1 parent b3a8027 commit 36ed4af

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pyiceberg/catalog/rest/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ def _config_headers(self, session: Session) -> None:
617617
session.headers.update(header_properties)
618618
session.headers["Content-type"] = "application/json"
619619
session.headers["User-Agent"] = f"PyIceberg/{__version__}"
620+
session.headers["X-Client-Version"] = f"PyIceberg {__version__}"
620621
session.headers.setdefault("X-Iceberg-Access-Delegation", ACCESS_DELEGATION_DEFAULT)
621622

622623
def _create_table(

tests/catalog/test_rest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,12 @@ def test_auth_header(rest_mock: Mocker) -> None:
19441944
assert mock_request.last_request.text == "grant_type=client_credentials&client_id=client&client_secret=secret&scope=catalog"
19451945

19461946

1947+
def test_client_version_header(rest_mock: Mocker) -> None:
1948+
catalog = RestCatalog("rest", uri=TEST_URI, warehouse="s3://some-bucket")
1949+
assert catalog._session.headers.get("X-Client-Version") == f"PyIceberg {pyiceberg.__version__}"
1950+
assert rest_mock.last_request.headers["X-Client-Version"] == f"PyIceberg {pyiceberg.__version__}"
1951+
1952+
19471953
class TestRestCatalogClose:
19481954
"""Tests RestCatalog close functionality"""
19491955

0 commit comments

Comments
 (0)