200 Response without body and content-type #3097
-
How can I make an endpoint return a Response without a body and without a content-type? Returning |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@bunny-therapist setting the status code to 204 should work. from litestar import get
from litestar.app import Litestar
from litestar.enums import MediaType
from litestar.testing import create_test_client
from http import HTTPStatus
@get("/", status_code=HTTPStatus.NO_CONTENT)
async def handler() -> None:
return None
with create_test_client([handler]) as client:
resp = client.get("/")
header = resp.headers
assert "content-type" not in resp.headers
assert resp.num_bytes_downloaded == 0 |
Beta Was this translation helpful? Give feedback.
-
"200 without a body" isn't really a thing. As @guacs said, if you truly want to omit the body, you should use a @get("/")
async def handler() -> str:
return "" which sends an empty plaintext response. |
Beta Was this translation helpful? Give feedback.
"200 without a body" isn't really a thing. As @guacs said, if you truly want to omit the body, you should use a
204
code. However, if you're fine with sending an empty body, you could just do something likewhich sends an empty plaintext response.