Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a docstring to Request.respond() #2409

Merged
merged 5 commits into from
Mar 14, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion sanic/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,22 @@ async def respond(
status: int = 200,
headers: Optional[Union[Header, Dict[str, str]]] = None,
content_type: Optional[str] = None,
):
) -> HTTPResponse:
"""Respond to the request without returning.

This method can only be called once, as you can only respond once.
It is useful if you wish to respond to the request without returning
from the handler.

If `response` is not passed, a response will be created from the
`status`, `headers` and `content_type` keyword arguments.

:param response: response instance to send
:param status: status code to return in the response
:param headers: headers to return in the response
:param content_type: Content-Type of the response
:return: final response sent (may have changed because of middlewares)
Bluenix2 marked this conversation as resolved.
Show resolved Hide resolved
"""
try:
if self.stream is not None and self.stream.response:
raise ServerError("Second respond call is not allowed.")
Expand Down