]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 18 Jun 2023 09:55:42 +0000 (11:55 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 18 Jun 2023 09:55:42 +0000 (11:55 +0200)
- some link[href] results from nodeinfo may not have complete URLs
- strange, but true. they need to be prepended with https://{domain}

fba/federation.py
fba/networks/mastodon.py
fba/networks/pleroma.py

index 9ccbc60337fc46ab9e3dbea2b1493118f2f3b6f8..97dc78666d1e9e552d88139a551a76099d05044a 100644 (file)
@@ -252,7 +252,7 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict:
         if path is None or path == request or path == f"http://{domain}{path}" or path == f"https://{domain}{path}":
             # DEBUG: print(f"DEBUG: Fetching request='{request}' from domain='{domain}' ...")
             if path == f"http://{domain}{path}" or path == f"https://{domain}{path}":
-                print(f"DEBUG: domain='{domain}',path='{path}' has protocol in path, splitting ...")
+                # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}' has protocol in path, splitting ...")
                 components = urlparse(path)
                 path = components.path
 
@@ -315,9 +315,18 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict:
                 if not isinstance(link, dict) or not "rel" in link:
                     print(f"WARNING: link[]='{type(link)}' is not 'dict' or no element 'rel' found")
                 elif link["rel"] in nodeinfo_identifier:
-                    # DEBUG: print("DEBUG: Fetching nodeinfo from:", link["href"])
+                    # Default is that 'href' has a complete URL, but some hosts don't send that
+                    url = link["href"]
+                    components = urlparse(link["href"])
+
+                    # DEBUG: print(f"DEBUG: components[{type(components)}]='{components}'")
+                    if components.scheme == "" and components.netloc == "":
+                        # DEBUG: print(f"DEBUG: link[href]='{link['href']}' has no scheme and host name in it, prepending from domain='{domain}'")
+                        url = f"https://{domain}{url}"
+
+                    # DEBUG: print("DEBUG: Fetching nodeinfo from:", url)
                     data = network.fetch_api_url(
-                        link["href"],
+                        url,
                         (config.get("connection_timeout"), config.get("read_timeout"))
                      )
 
@@ -365,7 +374,7 @@ def fetch_generator_from_path(domain: str, path: str = "/") -> str:
 
         # DEBUG: print(f"DEBUG: generator='{generator}',site_name='{site_name}'")
         if isinstance(generator, bs4.element.Tag) and isinstance(generator.get("content"), str):
-            print("DEBUG: Found generator meta tag:", domain)
+            # DEBUG: print("DEBUG: Found generator meta tag:", domain)
             software = tidyup.domain(generator.get("content"))
             # DEBUG: print(f"DEBUG: software[{type(software)}]='{software}'")
             if software is not None and software != "":
index 7d836eda618371a34e346f8bb13046c81ae128e3..293b8ddb2cc7e57d2deda9e23ab12017dacb0457 100644 (file)
@@ -232,7 +232,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 print("WARNING: block_level is empty, domain:", domain)
                 continue
             elif block_level == "accept":
-                print(f"DEBUG: domain='{domain}' skipping block_level='accept'")
+                # DEBUG: print(f"DEBUG: domain='{domain}' skipping block_level='accept'")
                 continue
 
             # DEBUG: print(f"DEBUG: Checking {len(blocklist)} entries from domain='{domain}',software='mastodon',block_level='{block_level}' ...")
index f017df3c32dcbf56a0435aac2a7fa778615e968f..39ca927d4fe80248bd1c4c6c94480185d7419db9 100644 (file)
@@ -93,7 +93,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 print("WARNING: block_level is now empty!")
                 continue
             elif block_level == "accept":
-                print(f"DEBUG: domain='{domain}' skipping block_level='accept'")
+                # DEBUG: print(f"DEBUG: domain='{domain}' skipping block_level='accept'")
                 continue
 
             # DEBUG: print(f"DEBUG: Checking {len(blocklist)} entries from domain='{domain}',block_level='{block_level}' ...")
@@ -257,7 +257,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 print("WARNING: block_level is now empty!")
                 continue
             elif block_level == "accept":
-                print(f"DEBUG: domain='{domain}' skipping block_level='accept'")
+                # DEBUG: print(f"DEBUG: domain='{domain}' skipping block_level='accept'")
                 continue
 
             # DEBUG: print(f"DEBUG: Checking {len(info.items())} entries from domain='{domain}',software='pleroma',block_level='{block_level}' ...")