diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-05-20 07:57:07 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-05-20 07:57:07 +0000 |
commit | c94a711ca85e6d197d0dfdafd76de4900ce54224 (patch) | |
tree | 79f8b540942780a4bbd82f293ba7ca8773c4cab6 /heatclient/common | |
parent | 0e0959eb7ce63f795c0bdd5509c6cf7b04cd1de8 (diff) | |
parent | 01b7781f68e8b7a158ad874814f2a16d21f48505 (diff) | |
download | python-heatclient-c94a711ca85e6d197d0dfdafd76de4900ce54224.tar.gz |
Merge "Allow redirects to use location from response"
Diffstat (limited to 'heatclient/common')
-rw-r--r-- | heatclient/common/http.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/heatclient/common/http.py b/heatclient/common/http.py index 3770bc7..5517609 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -201,10 +201,14 @@ class HTTPClient(object): # See issue: https://github.com/kennethreitz/requests/issues/1704 allow_redirects = False + # Use fully qualified URL from response header for redirects + if not parse.urlparse(url).netloc: + url = self.endpoint_url + url + try: resp = requests.request( method, - self.endpoint_url + url, + url, allow_redirects=allow_redirects, **kwargs) except socket.gaierror as e: @@ -231,23 +235,15 @@ class HTTPClient(object): # unless caller specified redirect=False if redirect: location = resp.headers.get('location') - path = self.strip_endpoint(location) - resp = self._http_request(path, method, **kwargs) + if not location: + message = _("Location not returned with redirect") + raise exc.InvalidEndpoint(message=message) + resp = self._http_request(location, method, **kwargs) elif resp.status_code == 300: raise exc.from_response(resp) return resp - def strip_endpoint(self, location): - if location is None: - message = _("Location not returned with 302") - raise exc.InvalidEndpoint(message=message) - elif location.lower().startswith(self.endpoint.lower()): - return location[len(self.endpoint):] - else: - message = _("Prohibited endpoint redirect %s") % location - raise exc.InvalidEndpoint(message=message) - def credentials_headers(self): creds = {} # NOTE(dhu): (shardy) When deferred_auth_method=password, Heat |