Add HEAD as a sugar route

This commit is contained in:
Lucas Andrade 2021-05-15 00:18:52 -03:00
parent f64fff6476
commit b743948d3e
No known key found for this signature in database
GPG key ID: AB930A851A6F3D6E
2 changed files with 17 additions and 0 deletions

View file

@ -376,6 +376,13 @@ class Scaffold:
"""
return self._method_route("GET", rule, options)
def head(self, rule: str, **options: t.Any) -> t.Callable:
"""Shortcut for :meth:`route` with ``methods=["HEAD"]``.
.. versionadded:: 2.0
"""
return self._method_route("HEAD", rule, options)
def post(self, rule: str, **options: t.Any) -> t.Callable:
"""Shortcut for :meth:`route` with ``methods=["POST"]``.

View file

@ -60,6 +60,16 @@ def test_method_route(app, client, method):
assert client_method("/").data == b"Hello"
def test_head_method_route(app, client):
@app.head("/")
def index():
return flask.request.method
rv = client.head("/")
assert rv.status_code == 200
assert not rv.data
def test_method_route_no_methods(app):
with pytest.raises(TypeError):
app.get("/", methods=["GET", "POST"])