Skip to content

Commit 15def10

Browse files
committed
Include version in User-Agent string
1 parent 0fa563a commit 15def10

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pystac/stac_io.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,20 @@ def read_text_from_href(self, href: str) -> str:
302302
with urllib3.request(
303303
"GET",
304304
href,
305-
headers={"User-Agent": "pystac", **self.headers},
305+
headers={
306+
"User-Agent": f"pystac/{pystac.__version__}",
307+
**self.headers,
308+
},
306309
preload_content=False, # type: ignore
307310
) as f:
308311
href_contents = f.read().decode("utf-8")
309312
else:
310313
req = Request(
311-
href, headers={"User-Agent": "pystac", **self.headers}
314+
href,
315+
headers={
316+
"User-Agent": f"pystac/{pystac.__version__}",
317+
**self.headers,
318+
},
312319
)
313320
with urlopen(req) as f:
314321
href_contents = f.read().decode("utf-8")

tests/test_stac_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_headers_stac_io(request_mock: unittest.mock.MagicMock) -> None:
130130
pystac.Catalog.from_file("https://example.com/catalog.json", stac_io=stac_io)
131131

132132
headers = request_mock.call_args[1]["headers"]
133-
assert headers == {"User-Agent": "pystac", **stac_io.headers}
133+
assert headers == {"User-Agent": f"pystac/{pystac.__version__}", **stac_io.headers}
134134

135135

136136
@pytest.mark.vcr()

0 commit comments

Comments
 (0)