Skip to content

Commit

Permalink
refactor(utils): RequestHeaders constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
wvenialbo committed Oct 25, 2024
1 parent 1c7e829 commit 5e6d8a1
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/GOES_DL/utils/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,42 @@ def __init__(self, *, accept: str = TEXT_HTML) -> None:
The value of the "accept" header, by default TEXT_HTML
("text/html").
"""
user_agent: str = (
self._headers: dict[str, str] = self._build_headers(accept)

@staticmethod
def get_user_agent() -> str:
"""
Get the user agent string.
Returns
-------
str
The user agent string.
"""
return (
f"{__package_id__}/{__version__} "
f"({platform.system()} {os.name.upper()} "
f"{platform.release()}/{platform.version()})"
)

self._headers: dict[str, str] = {
@staticmethod
def _build_headers(accept: str) -> dict[str, str]:
"""
Build the headers dictionary.
Parameters
----------
accept : str
The value of the "accept" header.
Returns
-------
dict[str, str]
A dictionary containing the headers.
"""
user_agent: str = RequestHeaders.get_user_agent()

return {
"accept": accept,
"accept-encoding": "gzip, deflate, br, zstd",
"accept-language": ACCEPT_LANGUAGE,
Expand Down

0 comments on commit 5e6d8a1

Please sign in to comment.