diff --git a/apigateway/utils.py b/apigateway/utils.py index bf3b934..7d5756c 100644 --- a/apigateway/utils.py +++ b/apigateway/utils.py @@ -4,6 +4,8 @@ from functools import wraps from typing import Tuple from urllib.parse import urljoin +import re +import os import jsondiff as jd import requests @@ -251,8 +253,20 @@ def _construct_remote_url(self) -> str: Returns: str: The URL of the remote server. """ + verify_url_regex = re.compile(r"([12]\d\d\d[A-Za-z&\.]{5}[A-Za-z0-9\.]{9}[A-Z\.]/verify_url\:)(http[s]?\://)(.*)") + path = request.full_path.replace(self._deploy_path, "", 1) path = path[1:] if path.startswith("/") else path + #This block exists because of an incompatibility between urlparse.urljoin and urllib.parse.urljoin + #This incompatibility results in http(s):// -> http(s):/ if the proc spec occurs in the middle of the url. + try: + resolver_check = verify_url_regex.match(path) + if resolver_check: + resolver_groups = resolver_check.groups() + return str(self._remote_base_url) + "/" + os.path.normpath(resolver_groups[0]) \ + + resolver_groups[1] + os.path.normpath(resolver_groups[2]) + except ValueError: + current_app.logger.exception("Failed to properly check url path for resolver verify_url path.") return urljoin(self._remote_base_url, path)