Add HEAD as a sugar route
This commit is contained in:
parent
f64fff6476
commit
b743948d3e
2 changed files with 17 additions and 0 deletions
|
|
@ -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"]``.
|
||||
|
||||
|
|
|
|||
|
|
@ -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"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue