code: def make_complete_url(environ, localUri=None):
      
      url = environ["wsgi.url_scheme"] + "://"
  
      if environ.get("HTTP_HOST"):
          url += environ["HTTP_HOST"]
      else:
          url += environ["SERVER_NAME"]
  
          if environ["wsgi.url_scheme"] == "https":
              if environ["SERVER_PORT"] != "443":
                  url += ":" + environ["SERVER_PORT"]
          else:
              if environ["SERVER_PORT"] != "80":
                  url += ":" + environ["SERVER_PORT"]
  
      url += compat.quote(environ.get("SCRIPT_NAME", ""))
  
      if localUri is None:
          url += compat.quote(environ.get("PATH_INFO", ""))
          if environ.get("QUERY_STRING"):
              url += "?" + environ["QUERY_STRING"]
      else:
          url += localUri  # TODO: quote?
      return url
docs: URL reconstruction according to PEP 333.
      @see https://www.python.org/dev/peps/pep-3333/#url-reconstruction