summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2018-08-22 14:33:02 +0100
committerDomen Kožar <domen@dev.si>2018-08-22 14:57:51 +0100
commitb5422eeefe5fd3b963115b3c58a08ed8a15b8a88 (patch)
tree286e4816469db46c234bdc992490cb2d66f77d1b
parent5488da0d165468199f0d07a2ca579b86617fad72 (diff)
downloadpyramid-b5422eeefe5fd3b963115b3c58a08ed8a15b8a88.tar.gz
pyramid-b5422eeefe5fd3b963115b3c58a08ed8a15b8a88.tar.bz2
pyramid-b5422eeefe5fd3b963115b3c58a08ed8a15b8a88.zip
add_notfound_view: use HTTPTemporaryRedirect as default
-rw-r--r--pyramid/config/views.py17
-rw-r--r--pyramid/tests/test_config/test_views.py4
-rw-r--r--pyramid/tests/test_integration.py4
-rw-r--r--pyramid/tests/test_view.py6
-rw-r--r--pyramid/view.py10
5 files changed, 26 insertions, 15 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index eb002ec2d..5d46de276 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -1631,8 +1631,8 @@ class ViewsConfiguratorMixin(object):
instead implements :class:`~pyramid.interfaces.IResponse`, the
append_slash logic will behave as if ``append_slash=True`` was passed,
but the provided class will be used as the response class instead of
- the default :class:`~pyramid.httpexceptions.HTTPFound` response class
- when a redirect is performed. For example:
+ the default :class:`~pyramid.httpexceptions.HTTPTemporaryRedirect`
+ response class when a redirect is performed. For example:
.. code-block:: python
@@ -1640,10 +1640,15 @@ class ViewsConfiguratorMixin(object):
config.add_notfound_view(append_slash=HTTPMovedPermanently)
The above means that a redirect to a slash-appended route will be
- attempted, but instead of :class:`~pyramid.httpexceptions.HTTPFound`
+ attempted, but instead of :class:`~pyramid.httpexceptions.HTTPTemporaryRedirect`
being used, :class:`~pyramid.httpexceptions.HTTPMovedPermanently will
be used` for the redirect response if a slash-appended route is found.
+ :class:`~pyramid.httpexceptions.HTTPTemporaryRedirect` class is used
+ as default response, which is equivalent to
+ :class:`~pyramid.httpexceptions.HTTPFound` with addition of redirecting
+ with the same HTTP method (useful when doing POST requests).
+
.. versionadded:: 1.3
.. versionchanged:: 1.6
@@ -1655,6 +1660,12 @@ class ViewsConfiguratorMixin(object):
.. versionchanged:: 1.8
The view is created using ``exception_only=True``.
+
+ .. versionchanged: 1.10
+
+ Default response was changed from :class:`~pyramid.httpexceptions.HTTPFound`
+ to :class:`~pyramid.httpexceptions.HTTPTemporaryRedirect`.
+
"""
for arg in (
'name', 'permission', 'context', 'for_', 'require_csrf',
diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py
index cb554a816..1c99d2ac5 100644
--- a/pyramid/tests/test_config/test_views.py
+++ b/pyramid/tests/test_config/test_views.py
@@ -2238,7 +2238,7 @@ class TestViewsConfigurationMixin(unittest.TestCase):
from pyramid.renderers import null_renderer
from zope.interface import implementedBy
from pyramid.interfaces import IRequest
- from pyramid.httpexceptions import HTTPFound, HTTPNotFound
+ from pyramid.httpexceptions import HTTPTemporaryRedirect, HTTPNotFound
config = self._makeOne(autocommit=True)
config.add_route('foo', '/foo/')
def view(request): return Response('OK')
@@ -2251,7 +2251,7 @@ class TestViewsConfigurationMixin(unittest.TestCase):
exc_iface=implementedBy(HTTPNotFound),
request_iface=IRequest)
result = view(None, request)
- self.assertTrue(isinstance(result, HTTPFound))
+ self.assertTrue(isinstance(result, HTTPTemporaryRedirect))
self.assertEqual(result.location, '/scriptname/foo/?a=1&b=2')
def test_add_notfound_view_append_slash_custom_response(self):
diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py
index f23e54609..c99e89f59 100644
--- a/pyramid/tests/test_integration.py
+++ b/pyramid/tests/test_integration.py
@@ -386,11 +386,11 @@ class TestNotFoundView(IntegrationBase, unittest.TestCase):
def test_it(self):
res = self.testapp.get('/wontbefound', status=200)
self.assertTrue(b'generic_notfound' in res.body)
- res = self.testapp.get('/bar', status=302)
+ res = self.testapp.get('/bar', status=307)
self.assertEqual(res.location, 'http://localhost/bar/')
res = self.testapp.get('/bar/', status=200)
self.assertTrue(b'OK bar' in res.body)
- res = self.testapp.get('/foo', status=302)
+ res = self.testapp.get('/foo', status=307)
self.assertEqual(res.location, 'http://localhost/foo/')
res = self.testapp.get('/foo/', status=200)
self.assertTrue(b'OK foo2' in res.body)
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py
index 0124ce632..3344bd739 100644
--- a/pyramid/tests/test_view.py
+++ b/pyramid/tests/test_view.py
@@ -686,7 +686,7 @@ class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
context = ExceptionResponse()
self._registerMapper(request.registry, True)
response = self._callFUT(context, request)
- self.assertEqual(response.status, '302 Found')
+ self.assertEqual(response.status, '307 Temporary Redirect')
self.assertEqual(response.location, '/abc/')
def test_matches_with_script_name(self):
@@ -694,7 +694,7 @@ class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
context = ExceptionResponse()
self._registerMapper(request.registry, True)
response = self._callFUT(context, request)
- self.assertEqual(response.status, '302 Found')
+ self.assertEqual(response.status, '307 Temporary Redirect')
self.assertEqual(response.location, '/foo/abc/')
def test_with_query_string(self):
@@ -702,7 +702,7 @@ class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
context = ExceptionResponse()
self._registerMapper(request.registry, True)
response = self._callFUT(context, request)
- self.assertEqual(response.status, '302 Found')
+ self.assertEqual(response.status, '307 Temporary Redirect')
self.assertEqual(response.location, '/abc/?a=1&b=2')
class TestAppendSlashNotFoundViewFactory(BaseTest, unittest.TestCase):
diff --git a/pyramid/view.py b/pyramid/view.py
index d1a12df32..769328344 100644
--- a/pyramid/view.py
+++ b/pyramid/view.py
@@ -24,8 +24,8 @@ from pyramid.exceptions import (
)
from pyramid.httpexceptions import (
- HTTPFound,
HTTPNotFound,
+ HTTPTemporaryRedirect,
default_exceptionresponse_view,
)
@@ -292,7 +292,7 @@ class AppendSlashNotFoundViewFactory(object):
.. deprecated:: 1.3
"""
- def __init__(self, notfound_view=None, redirect_class=HTTPFound):
+ def __init__(self, notfound_view=None, redirect_class=HTTPTemporaryRedirect):
if notfound_view is None:
notfound_view = default_exceptionresponse_view
self.notfound_view = notfound_view
@@ -377,8 +377,8 @@ class notfound_view_config(object):
instead implements :class:`~pyramid.interfaces.IResponse`, the
append_slash logic will behave as if ``append_slash=True`` was passed,
but the provided class will be used as the response class instead of
- the default :class:`~pyramid.httpexceptions.HTTPFound` response class
- when a redirect is performed. For example:
+ the default :class:`~pyramid.httpexceptions.HTTPTemporaryRedirect`
+ response class when a redirect is performed. For example:
.. code-block:: python
@@ -392,7 +392,7 @@ class notfound_view_config(object):
return HTTPNotFound('not found')
The above means that a redirect to a slash-appended route will be
- attempted, but instead of :class:`~pyramid.httpexceptions.HTTPFound`
+ attempted, but instead of :class:`~pyramid.httpexceptions.HTTPTemporaryRedirect`
being used, :class:`~pyramid.httpexceptions.HTTPMovedPermanently will
be used` for the redirect response if a slash-appended route is found.