diff options
| author | Chris McDonough <chrism@plope.com> | 2012-03-30 05:42:47 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-03-30 05:42:47 -0400 |
| commit | 360f251a1765e53a15bec53c91068880f47e503f (patch) | |
| tree | 31646cadc1aa05ee8dfacd39c2e17504ff0fdb42 | |
| parent | 1794b4b17482314bfc57285a71b78fce091870c3 (diff) | |
| download | pyramid-360f251a1765e53a15bec53c91068880f47e503f.tar.gz pyramid-360f251a1765e53a15bec53c91068880f47e503f.tar.bz2 pyramid-360f251a1765e53a15bec53c91068880f47e503f.zip | |
- As of this release, the ``request_method`` predicate, when used, will also
imply that ``HEAD`` is implied when you use ``GET``. For example, using
``@view_config(request_method='GET')`` is equivalent to using
``@view_config(request_method='HEAD')``. Using
``@view_config(request_method=('GET', 'POST')`` is equivalent to using
``@view_config(request_method=('GET', 'HEAD', 'POST')``. This is because
HEAD is a variant of GET that omits the body, and WebOb has special support
to return an empty body when a HEAD is used.
| -rw-r--r-- | CHANGES.txt | 8 | ||||
| -rw-r--r-- | pyramid/config/views.py | 6 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_views.py | 10 |
3 files changed, 23 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 9cddc01b5..f0fef62ea 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,3 +17,11 @@ Features values natively serializable by ``json.dumps`` (such as ints, lists, dictionaries, strings, and so forth). +- As of this release, the ``request_method`` predicate, when used, will also + imply that ``HEAD`` is implied when you use ``GET``. For example, using + ``@view_config(request_method='GET')`` is equivalent to using + ``@view_config(request_method='HEAD')``. Using + ``@view_config(request_method=('GET', 'POST')`` is equivalent to using + ``@view_config(request_method=('GET', 'HEAD', 'POST')``. This is because + HEAD is a variant of GET that omits the body, and WebOb has special support + to return an empty body when a HEAD is used. diff --git a/pyramid/config/views.py b/pyramid/config/views.py index a79d20d7d..ad4df28d8 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -865,7 +865,8 @@ class ViewsConfiguratorMixin(object): declaration with this argument ensures that the view will only be called when the request's ``method`` attribute (aka the ``REQUEST_METHOD`` of the WSGI environment) string matches a - supplied value. + supplied value. Note that use of ``GET`` also implies that the + view will respond to ``HEAD`` as of Pyramid 1.4. .. note:: The ability to pass a tuple of items as ``request_method`` is new as of Pyramid 1.2. Previous @@ -996,6 +997,9 @@ class ViewsConfiguratorMixin(object): if request_method is not None: request_method = as_sorted_tuple(request_method) + if 'GET' in request_method and 'HEAD' not in request_method: + # GET implies HEAD too + request_method = as_sorted_tuple(request_method + ('HEAD',)) order, predicates, phash = make_predicates(xhr=xhr, request_method=request_method, path_info=path_info, diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index 98fe3d1cd..9b46f83c9 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -1146,6 +1146,16 @@ class TestViewsConfigurationMixin(unittest.TestCase): request.method = 'GET' self._assertNotFound(wrapper, None, request) + def test_add_view_with_request_method_get_implies_head(self): + from pyramid.renderers import null_renderer + view = lambda *arg: 'OK' + config = self._makeOne(autocommit=True) + config.add_view(view=view, request_method='GET', renderer=null_renderer) + wrapper = self._getViewCallable(config) + request = self._makeRequest(config) + request.method = 'HEAD' + self.assertEqual(wrapper(None, request), 'OK') + def test_add_view_with_request_param_noval_true(self): from pyramid.renderers import null_renderer view = lambda *arg: 'OK' |
