diff --git a/src/flask/scaffold.py b/src/flask/scaffold.py index f50c9b1b..66be5b46 100644 --- a/src/flask/scaffold.py +++ b/src/flask/scaffold.py @@ -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"]``. diff --git a/tests/test_basic.py b/tests/test_basic.py index 2cb96794..e7ac0fc9 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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"])