Skip to content

Commit

Permalink
feat: Added a default user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 19, 2024
1 parent 3bd3770 commit 6740d33
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(
super().__init__(name=name, schema=schema, tap=tap)
if path:
self.path = path
self._http_headers: dict = {}
self._http_headers: dict = {"User-Agent": self.user_agent}
self._requests_session = requests.Session()
self._compiled_jsonpath = None
self._next_page_token_compiled_jsonpath = None
Expand Down Expand Up @@ -157,6 +157,15 @@ def requests_session(self) -> requests.Session:
self._requests_session = requests.Session()
return self._requests_session

@property
def user_agent(self) -> str:
"""Get the user agent string for the stream.
Returns:
The user agent string.
"""
return f"{self.tap_name}/{self._tap.plugin_version}"

def validate_response(self, response: requests.Response) -> None:
"""Validate HTTP response.
Expand Down Expand Up @@ -560,10 +569,7 @@ def http_headers(self) -> dict:
Returns:
Dictionary of HTTP headers to use as a base for every request.
"""
result = self._http_headers
if "user_agent" in self.config:
result["User-Agent"] = self.config.get("user_agent")
return result
return self._http_headers

@property
def timeout(self) -> int:
Expand Down

0 comments on commit 6740d33

Please sign in to comment.