]> git.scottworley.com Git - paperdoorknob/commitdiff
fetch: Send User-Agent header
authorScott Worley <scottworley@scottworley.com>
Fri, 29 Dec 2023 06:48:17 +0000 (22:48 -0800)
committerScott Worley <scottworley@scottworley.com>
Fri, 29 Dec 2023 06:48:17 +0000 (22:48 -0800)
fetch.py

index b99938c055fe8a2fc31f951404ed497849e5dcff..151e2a981eca71b2d07e8b7713a687fd7748de5a 100644 (file)
--- a/fetch.py
+++ b/fetch.py
@@ -14,6 +14,10 @@ import requests
 import requests_cache
 
 
+_headers = {
+    'User-Agent': 'paperdoorknob/0.0.1 (https://git.scottworley.com/paperdoorknob/)'}
+
+
 class Fetcher(ABC):
     @abstractmethod
     def fetch(self, url: str) -> bytes:
@@ -27,7 +31,7 @@ class _SessionFetcher(Fetcher):
         self._timeout = timeout
 
     def fetch(self, url: str) -> bytes:
-        with self._session.get(url, timeout=self._timeout) as r:
+        with self._session.get(url, timeout=self._timeout, headers=_headers) as r:
             r.raise_for_status()
             return r.content
 
@@ -44,7 +48,7 @@ class _CachingFetcher(Fetcher):
         self._cache_hit_count = 0
 
     def fetch(self, url: str) -> bytes:
-        with self._session.get(url, timeout=self._timeout) as r:
+        with self._session.get(url, timeout=self._timeout, headers=_headers) as r:
             r.raise_for_status()
             self._request_count += 1
             self._cache_hit_count += int(r.from_cache)