From 5e6d8a1b415b31fe6633c4f0cbb06acad5ae6369 Mon Sep 17 00:00:00 2001 From: wvenialbo Date: Fri, 25 Oct 2024 02:08:43 -0300 Subject: [PATCH] refactor(utils): RequestHeaders constructor --- src/GOES_DL/utils/headers.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/GOES_DL/utils/headers.py b/src/GOES_DL/utils/headers.py index 593cafa..132968f 100644 --- a/src/GOES_DL/utils/headers.py +++ b/src/GOES_DL/utils/headers.py @@ -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,