Use urlparse.urlunsplit() to join url parts together.

This also works when there is no scheme and no hostname.
This commit is contained in:
2016-08-23 14:34:15 +02:00
parent 00a34e7e24
commit 751c692e6a

View File

@@ -21,11 +21,12 @@ class FlaskInternalApi(pillarsdk.Api):
"""Fakes a http call through Flask/Werkzeug.""" """Fakes a http call through Flask/Werkzeug."""
client = current_app.test_client() client = current_app.test_client()
self.requests_to_flask_kwargs(kwargs) self.requests_to_flask_kwargs(kwargs)
url = urlparse.urlsplit(url)
path = url.scheme + "://" + url.netloc + url.path # Leave out the query string and fragment from the URL.
query = url.query split_url = urlparse.urlsplit(url)
path = urlparse.urlunsplit(split_url[:-2] + (None, None))
try: try:
response = client.open(path=path, query_string=query, method=method, response = client.open(path=path, query_string=split_url.query, method=method,
**kwargs) **kwargs)
except Exception as ex: except Exception as ex:
log.warning('Error performing HTTP %s request to %s: %s', method, log.warning('Error performing HTTP %s request to %s: %s', method,