[svn r33] HTTP response code 307 - Temporary Redirect

This commit is contained in:
sardonyx.linden
2007-10-25 13:24:54 -04:00
parent 00451d6de6
commit af2682d759
2 changed files with 36 additions and 10 deletions

View File

@@ -279,6 +279,11 @@ class NotModified(ConnectionError):
""" 304 Not Modified """
pass
class TemporaryRedirect(Retriable):
""" 307 Temporary Redirect """
pass
class BadRequest(ConnectionError):
""" 400 Bad Request """
@@ -311,6 +316,7 @@ status_to_error_map = {
302: Found,
303: SeeOther,
304: NotModified,
307: TemporaryRedirect,
400: BadRequest,
403: Forbidden,
404: NotFound,

View File

@@ -211,15 +211,21 @@ class TestHttpc(TestBase, tests.TestCase):
lambda: httpc.delete(self.base_url() + 'b0gu5'))
class Site301(BasicSite):
class RedirectSite(BasicSite):
response_code = 301
def handle_request(self, req):
if req.path().startswith('/redirect/'):
url = ('http://' + req.get_header('host') +
req.uri().replace('/redirect/', '/'))
req.response(301, headers={'location': url}, body='')
req.response(self.response_code, headers={'location': url},
body='')
return
return Site.handle_request(self, req)
class Site301(RedirectSite):
pass
class Site302(BasicSite):
def handle_request(self, req):
@@ -239,14 +245,12 @@ class Site302(BasicSite):
return Site.handle_request(self, req)
class Site303(BasicSite):
def handle_request(self, req):
if req.path().startswith('/redirect/'):
url = ('http://' + req.get_header('host') +
req.uri().replace('/redirect/', '/'))
req.response(303, headers={'location': url}, body='')
return
return Site.handle_request(self, req)
class Site303(RedirectSite):
response_code = 303
class Site307(RedirectSite):
response_code = 307
class TestHttpc301(TestBase, tests.TestCase):
@@ -309,5 +313,21 @@ class TestHttpc303(TestBase, tests.TestCase):
self.assertEquals(response, data)
class TestHttpc307(TestBase, tests.TestCase):
site_class = Site307
def base_url(self):
return 'http://localhost:31337/redirect/'
def test_post(self):
data = 'hello world'
try:
response = httpc.post(self.base_url() + 'hello', data=data)
self.assert_(False)
except httpc.TemporaryRedirect, err:
response = err.retry()
self.assertEquals(response, data)
if __name__ == '__main__':
tests.main()