summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-12-28 19:02:17 +0000
committerGerrit Code Review <review@openstack.org>2013-12-28 19:02:17 +0000
commit85cfce17f5e1e74dd10f8d7a4bdcbc8a8422bb32 (patch)
treef3b28a8f95a0833f5961068b05eb78015e9198d7
parent9a0fa4eb56360f1fcd0cfbac3975c065cd021ff8 (diff)
parent6728bf3ccbfb79dc53f581e0d7e9019626c97df0 (diff)
downloadpython-keystoneclient-85cfce17f5e1e74dd10f8d7a4bdcbc8a8422bb32.tar.gz
Merge "Move redirect handling to session"
-rw-r--r--keystoneclient/httpclient.py11
-rw-r--r--keystoneclient/session.py24
2 files changed, 20 insertions, 15 deletions
diff --git a/keystoneclient/httpclient.py b/keystoneclient/httpclient.py
index b1d03e5..fa2bbb4 100644
--- a/keystoneclient/httpclient.py
+++ b/keystoneclient/httpclient.py
@@ -545,17 +545,6 @@ class HTTPClient(object):
pass
resp = self.session.request(url, method, **kwargs)
-
- # NOTE(jamielennox): The requests lib will handle the majority of
- # redirections. Where it fails is when POSTs are redirected which
- # is apparently something handled differently by each browser which
- # requests forces us to do the most compliant way (which we don't want)
- # see: https://en.wikipedia.org/wiki/Post/Redirect/Get
- # Nova and other direct users don't do this. Is it still relevant?
- if resp.status_code in (301, 302, 305):
- # Redirected. Reissue the request to the new location.
- return self.request(resp.headers['location'], method, **kwargs)
-
return resp, self._decode_body(resp)
def _cs_request(self, url, method, **kwargs):
diff --git a/keystoneclient/session.py b/keystoneclient/session.py
index 3e234e4..5382ee9 100644
--- a/keystoneclient/session.py
+++ b/keystoneclient/session.py
@@ -149,6 +149,16 @@ class Session(object):
if data:
_logger.debug('REQ BODY: %s', data)
+ resp = self._send_request(url, method, **kwargs)
+
+ if resp.status_code >= 400:
+ _logger.debug('Request returned failure status: %s',
+ resp.status_code)
+ raise exceptions.from_response(resp, method, url)
+
+ return resp
+
+ def _send_request(self, url, method, **kwargs):
try:
resp = self.session.request(method, url, **kwargs)
except requests.exceptions.SSLError:
@@ -164,10 +174,16 @@ class Session(object):
_logger.debug('RESP: [%s] %s\nRESP BODY: %s\n',
resp.status_code, resp.headers, resp.text)
- if resp.status_code >= 400:
- _logger.debug('Request returned failure status: %s',
- resp.status_code)
- raise exceptions.from_response(resp, method, url)
+ # NOTE(jamielennox): The requests lib will handle the majority of
+ # redirections. Where it fails is when POSTs are redirected which
+ # is apparently something handled differently by each browser which
+ # requests forces us to do the most compliant way (which we don't want)
+ # see: https://en.wikipedia.org/wiki/Post/Redirect/Get
+ # Nova and other direct users don't do this. Is it still relevant?
+ if resp.status_code in (301, 302, 305):
+ # Redirected. Reissue the request to the new location.
+ return self._send_request(resp.headers['location'],
+ method, **kwargs)
return resp