# Fetch / to check for meta tag indicating csrf
logger.debug("Fetching / from domain='%s' for CSRF check ...", domain)
- response = network.fetch_response(
+ response = network.get_generic(
domain,
- "/",
- headers=network.web_headers,
- timeout=(config.get("connection_timeout"), config.get("read_timeout"))
+ "/"
)
logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
software = None
logger.debug("Fetching path='%s' from domain='%s' ...", path, domain)
- response = network.fetch_response(
+ response = network.get_generic(
domain,
path,
- headers=network.web_headers,
- timeout=(config.get("connection_timeout"), config.get("read_timeout")),
allow_redirects=True
)
raise ValueError(f"headers[]='{type(headers)}' is not of type 'dict'")
elif not isinstance(timeout, tuple):
raise ValueError(f"timeout[]='{type(timeout)}' is not of type 'tuple'")
+ elif not isinstance(allow_redirects, bool):
+ raise ValueError(f"allow_redirects[]='{type(allow_redirects)}' is not of type 'bool'")
start = 0
try:
logger.debug("rows()=%d - EXIT!", len(rows))
return rows
+
+def get_generic(domain: str, path: str, allow_redirects: bool = False) -> requests.models.Response:
+ logger.debug("domain='%s',path='%s',allow_redirects='%s' - CALLED!", domain, path, allow_redirects)
+ domain_helper.raise_on(domain)
+
+ if blacklist.is_blacklisted(domain):
+ raise ValueError(f"domain='{domain}' is blacklisted but function was invoked")
+ elif not isinstance(path, str):
+ raise ValueError(f"Parameter path[]='{type(path)}' is not of type 'str'")
+ elif path == "":
+ raise ValueError("Parameter 'path' is empty")
+ elif not path.startswith("/"):
+ raise ValueError(f"path='{path}' does not start with / but should")
+ elif not isinstance(allow_redirects, bool):
+ raise ValueError(f"allow_redirects[]='{type(allow_redirects)}' is not of type 'bool'")
+
+ logger.debug("Fetching path='%s' from domain='%s' ...", path, domain)
+ response = fetch_response(
+ domain,
+ path,
+ headers=web_headers,
+ allow_redirects=allow_redirects
+ )
+
+ logger.debug("response[]='%s' - EXIT!", type(response))
+ return response
try:
logger.debug("Fetching friendica blocks from domain='%s' ...", domain)
- raw = network.fetch_response(
+ raw = network.get_generic(
domain,
- "/friendica",
- network.web_headers,
- (config.get("connection_timeout"), config.get("read_timeout"))
+ "/friendica"
).text
logger.debug("Parsing %d Bytes ...", len(raw))
try:
# json endpoint for newer mastodongs
logger.debug("Fetching /instances from domain='%s'", domain)
- response = network.fetch_response(
+ response = network.get_generic(
domain,
- "/instances",
- network.web_headers,
- (config.get("connection_timeout"), config.get("read_timeout"))
+ "/instances"
)
logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
try:
# json endpoint for newer mastodongs
logger.debug("Fetching /instances from domain='%s'", domain)
- response = network.fetch_response(
+ response = network.get_generic(
domain,
- "/instances",
- network.web_headers,
- (config.get("connection_timeout"), config.get("read_timeout"))
+ "/instances"
)
logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))
logger.info("Fetching mastodon blocks from domain='%s'", domain)
for path in ["/about/more", "/about"]:
+ logger.debug("path='%s'", path)
try:
logger.debug("Fetching path='%s' from domain='%s' ...", path, domain)
doc = bs4.BeautifulSoup(
- network.fetch_response(
+ network.get_generic(
domain,
- path,
- network.web_headers,
- (config.get("connection_timeout"), config.get("read_timeout"))
+ path
).text,
"html.parser",
)
doc = None
logger.debug("Fetching path='%s' from domain='%s' ...", path, domain)
- response = network.fetch_response(
+ response = network.get_generic(
domain,
- path,
- network.web_headers,
- (config.get("connection_timeout"), config.get("read_timeout"))
+ path
)
logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text))