from fba import config
from fba import network
+from fba.helpers import cookies
+
def determine(domain: str, headers: dict) -> dict:
# DEBUG: print(f"DEBUG: domain='{domain}',headers()={len(headers)} - CALLED!")
if not isinstance(domain, str):
# DEBUG: print(f"DEBUG: response.ok='{response.ok}',response.status_code={response.status_code},response.text()={len(response.text)}")
if response.ok and len(response.text) > 0:
+ # Save cookies
+ cookies.store(domain, response.cookies.get_dict())
+
+ # Parse text
meta = bs4.BeautifulSoup(
response.text,
"html.parser"
--- /dev/null
+# Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
+# Copyright (C) 2023 Free Software Foundation
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+# Cookies stor
+_cookies = {}
+
+def store (domain: str, cookies: dict):
+ # DEBUG: print(f"DEBUG: domain='{domain}',cookies()={len(cookies)} - CALLED!")
+ if not isinstance(domain, str):
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
+ elif domain == "":
+ raise ValueError("Parameter 'domain' is empty")
+ elif not isinstance(cookies, dict):
+ raise ValueError(f"Parameter cookies[]='{type(cookies)}' is not 'dict'")
+
+ _cookies[domain] = cookies
+
+ # DEBUG: print(f"DEBUG: EXIT!")
+
+def get_all(domain: str) -> dict:
+ # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+ if not isinstance(domain, str):
+ raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
+ elif domain == "":
+ raise ValueError("Parameter 'domain' is empty")
+ elif not domain in _cookies:
+ raise Exception(f"domain='{domain}' has no cookies stored, maybe invoke store() first?")
+
+ # DEBUG: print(f"DEBUG: _cookies[{domain}]()={len(_cookies[domain])} - EXIT!")
+ return _cookies[domain]
from fba import config
from fba import fba
+from fba.helpers import cookies
+
from fba.models import instances
# HTTP headers for non-API requests
f"https://{domain}{path}",
data=data,
headers={**api_headers, **headers},
- timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+ timeout=(config.get("connection_timeout"), config.get("read_timeout")),
+ cookies=cookies.get_all(domain)
)
json_reply["json"] = json_from_response(response)
response = reqto.get(
f"https://{domain}{path}",
headers={**api_headers, **headers},
- timeout=timeout
+ timeout=timeout,
+ cookies=cookies.get_all(domain)
)
except exceptions as exception:
response = reqto.get(
f"https://{domain}{path}",
headers=headers,
- timeout=timeout
+ timeout=timeout,
+ cookies=cookies.get_all(domain)
)
except exceptions as exception: