[svn r123] Fixed infinite redirect problem that Nat discovered.
This commit is contained in:
@@ -589,13 +589,27 @@ class HttpSuite(object):
|
|||||||
def head(self, *args, **kwargs):
|
def head(self, *args, **kwargs):
|
||||||
return self.head_(*args, **kwargs)[-1]
|
return self.head_(*args, **kwargs)[-1]
|
||||||
|
|
||||||
def get_(self, url, headers=None, use_proxy=False, ok=None, aux=None):
|
def get_(self, url, headers=None, use_proxy=False, ok=None, aux=None, max_retries=8):
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {}
|
headers = {}
|
||||||
headers['accept'] = self.fallback_content_type+';q=1,*/*;q=0'
|
headers['accept'] = self.fallback_content_type+';q=1,*/*;q=0'
|
||||||
return self.request_(_Params(url, 'GET', headers=headers,
|
def req():
|
||||||
loader=self.loader, dumper=self.dumper,
|
return self.request_(_Params(url, 'GET', headers=headers,
|
||||||
use_proxy=use_proxy, ok=ok, aux=aux))
|
loader=self.loader, dumper=self.dumper,
|
||||||
|
use_proxy=use_proxy, ok=ok, aux=aux))
|
||||||
|
def retry_response(err):
|
||||||
|
def doit():
|
||||||
|
return err.retry_()
|
||||||
|
return doit
|
||||||
|
retried = 0
|
||||||
|
while retried <= max_retries:
|
||||||
|
try:
|
||||||
|
return req()
|
||||||
|
except (Found, TemporaryRedirect, MovedPermanently, SeeOther), e:
|
||||||
|
if retried >= max_retries:
|
||||||
|
raise
|
||||||
|
retried += 1
|
||||||
|
req = retry_response(e)
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
return self.get_(*args, **kwargs)[-1]
|
return self.get_(*args, **kwargs)[-1]
|
||||||
|
@@ -263,11 +263,12 @@ class TestHttpc301(TestBase, tests.TestCase):
|
|||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
try:
|
try:
|
||||||
httpc.get(self.base_url() + 'hello')
|
httpc.get(self.base_url() + 'hello', max_retries=0)
|
||||||
self.assert_(False)
|
self.assert_(False)
|
||||||
except httpc.MovedPermanently, err:
|
except httpc.MovedPermanently, err:
|
||||||
response = err.retry()
|
response = err.retry()
|
||||||
self.assertEquals(response, 'hello world')
|
self.assertEquals(response, 'hello world')
|
||||||
|
self.assertEquals(httpc.get(self.base_url() + 'hello', max_retries=1), 'hello world')
|
||||||
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
data = 'qunge'
|
data = 'qunge'
|
||||||
@@ -284,19 +285,21 @@ class TestHttpc302(TestBase, tests.TestCase):
|
|||||||
|
|
||||||
def test_get_expired(self):
|
def test_get_expired(self):
|
||||||
try:
|
try:
|
||||||
httpc.get(self.base_url() + 'expired/hello')
|
httpc.get(self.base_url() + 'expired/hello', max_retries=0)
|
||||||
self.assert_(False)
|
self.assert_(False)
|
||||||
except httpc.Found, err:
|
except httpc.Found, err:
|
||||||
response = err.retry()
|
response = err.retry()
|
||||||
self.assertEquals(response, 'hello world')
|
self.assertEquals(response, 'hello world')
|
||||||
|
self.assertEquals(httpc.get(self.base_url() + 'expired/hello', max_retries=1), 'hello world')
|
||||||
|
|
||||||
def test_get_expires(self):
|
def test_get_expires(self):
|
||||||
try:
|
try:
|
||||||
httpc.get(self.base_url() + 'expires/hello')
|
httpc.get(self.base_url() + 'expires/hello', max_retries=0)
|
||||||
self.assert_(False)
|
self.assert_(False)
|
||||||
except httpc.Found, err:
|
except httpc.Found, err:
|
||||||
response = err.retry()
|
response = err.retry()
|
||||||
self.assertEquals(response, 'hello world')
|
self.assertEquals(response, 'hello world')
|
||||||
|
self.assertEquals(httpc.get(self.base_url() + 'expires/hello', max_retries=1), 'hello world')
|
||||||
|
|
||||||
|
|
||||||
class TestHttpc303(TestBase, tests.TestCase):
|
class TestHttpc303(TestBase, tests.TestCase):
|
||||||
|
Reference in New Issue
Block a user