]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 15 Jun 2023 23:45:16 +0000 (01:45 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 15 Jun 2023 23:45:16 +0000 (01:45 +0200)
- rewrote block for fetching nodeinfo, fetch is provided path is None or matches
  with request or http[s]://domain/path
- if a protocol is given in 'path' parameter, then it needs to be removed

fba/federation.py

index 2d0b6d7c25d0eaf4a302e8a6b6d57fc2c61d3950..fc33f0dc09ce73db7a9d983bf6cba2ea86e187b1 100644 (file)
@@ -13,6 +13,8 @@
 # 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/>.
 
+from urllib.parse import urlparse
+
 import bs4
 import validators
 
@@ -245,26 +247,28 @@ def fetch_nodeinfo(domain: str, path: str = None) -> dict:
 
     for request in request_paths:
         # DEBUG: print(f"DEBUG: path[{type(path)}]='{path}',request='{request}'")
-        if path is not None and path != "" and path != request:
-            # DEBUG: print(f"DEBUG: path='{path}' does not match request='{request}' - SKIPPED!")
-            continue
-
-        # DEBUG: print(f"DEBUG: Fetching request='{request}' from domain='{domain}' ...")
-        data = network.get_json_api(
-            domain,
-            request,
-            headers,
-            (config.get("nodeinfo_connection_timeout"), config.get("nodeinfo_read_timeout"))
-        )
-
-        # DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code={response.status_code},data[]='{type(data)}'")
-        if "error_message" not in data:
-            # DEBUG: print("DEBUG: Success:", request)
-            instances.set_detection_mode(domain, "STATIC_CHECK")
-            instances.set_nodeinfo_url(domain, request)
-            break
-
-        print(f"WARNING: Failed fetching nodeinfo from domain='{domain}',status_code='{data['status_code']}',error_message='{data['error_message']}'")
+        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 ...")
+                components = urlparse(path)
+                path = components.path
+
+            data = network.get_json_api(
+                domain,
+                request,
+                headers,
+                (config.get("nodeinfo_connection_timeout"), config.get("nodeinfo_read_timeout"))
+            )
+
+            # DEBUG: print(f"DEBUG: response.ok={response.ok},response.status_code={response.status_code},data[]='{type(data)}'")
+            if "error_message" not in data:
+                # DEBUG: print("DEBUG: Success:", request)
+                instances.set_detection_mode(domain, "STATIC_CHECK")
+                instances.set_nodeinfo_url(domain, request)
+                break
+
+            print(f"WARNING: Failed fetching nodeinfo from domain='{domain}',status_code='{data['status_code']}',error_message='{data['error_message']}'")
 
     # DEBUG: print(f"DEBUG: data()={len(data)} - EXIT!")
     return data