mirror of https://github.com/tiangolo/fastapi.git
Merge 826cf946f3 into 272204c0c7
This commit is contained in:
commit
ce2c76846b
|
|
@ -344,7 +344,6 @@ def get_request_handler(
|
||||||
actual_response_class = response_class
|
actual_response_class = response_class
|
||||||
|
|
||||||
async def app(request: Request) -> Response:
|
async def app(request: Request) -> Response:
|
||||||
response: Union[Response, None] = None
|
|
||||||
file_stack = request.scope.get("fastapi_middleware_astack")
|
file_stack = request.scope.get("fastapi_middleware_astack")
|
||||||
assert isinstance(file_stack, AsyncExitStack), (
|
assert isinstance(file_stack, AsyncExitStack), (
|
||||||
"fastapi_middleware_astack not found in request scope"
|
"fastapi_middleware_astack not found in request scope"
|
||||||
|
|
@ -412,7 +411,6 @@ def get_request_handler(
|
||||||
raise http_error from e
|
raise http_error from e
|
||||||
|
|
||||||
# Solve dependencies and run path operation function, auto-closing dependencies
|
# Solve dependencies and run path operation function, auto-closing dependencies
|
||||||
errors: List[Any] = []
|
|
||||||
async_exit_stack = request.scope.get("fastapi_inner_astack")
|
async_exit_stack = request.scope.get("fastapi_inner_astack")
|
||||||
assert isinstance(async_exit_stack, AsyncExitStack), (
|
assert isinstance(async_exit_stack, AsyncExitStack), (
|
||||||
"fastapi_inner_astack not found in request scope"
|
"fastapi_inner_astack not found in request scope"
|
||||||
|
|
@ -426,7 +424,11 @@ def get_request_handler(
|
||||||
embed_body_fields=embed_body_fields,
|
embed_body_fields=embed_body_fields,
|
||||||
)
|
)
|
||||||
errors = solved_result.errors
|
errors = solved_result.errors
|
||||||
if not errors:
|
if errors:
|
||||||
|
raise RequestValidationError(
|
||||||
|
_normalize_errors(errors), body=body, endpoint_ctx=endpoint_ctx
|
||||||
|
)
|
||||||
|
|
||||||
raw_response = await run_endpoint_function(
|
raw_response = await run_endpoint_function(
|
||||||
dependant=dependant,
|
dependant=dependant,
|
||||||
values=solved_result.values,
|
values=solved_result.values,
|
||||||
|
|
@ -435,20 +437,15 @@ def get_request_handler(
|
||||||
if isinstance(raw_response, Response):
|
if isinstance(raw_response, Response):
|
||||||
if raw_response.background is None:
|
if raw_response.background is None:
|
||||||
raw_response.background = solved_result.background_tasks
|
raw_response.background = solved_result.background_tasks
|
||||||
response = raw_response
|
return raw_response
|
||||||
else:
|
|
||||||
response_args: Dict[str, Any] = {
|
response_args: Dict[str, Any] = {"background": solved_result.background_tasks}
|
||||||
"background": solved_result.background_tasks
|
|
||||||
}
|
|
||||||
# If status_code was set, use it, otherwise use the default from the
|
# If status_code was set, use it, otherwise use the default from the
|
||||||
# response class, in the case of redirect it's 307
|
# response class, in the case of redirect it's 307
|
||||||
current_status_code = (
|
|
||||||
status_code if status_code else solved_result.response.status_code
|
|
||||||
)
|
|
||||||
if current_status_code is not None:
|
|
||||||
response_args["status_code"] = current_status_code
|
|
||||||
if solved_result.response.status_code:
|
if solved_result.response.status_code:
|
||||||
response_args["status_code"] = solved_result.response.status_code
|
response_args["status_code"] = solved_result.response.status_code
|
||||||
|
elif status_code is not None:
|
||||||
|
response_args["status_code"] = status_code
|
||||||
content = await serialize_response(
|
content = await serialize_response(
|
||||||
field=response_field,
|
field=response_field,
|
||||||
response_content=raw_response,
|
response_content=raw_response,
|
||||||
|
|
@ -465,14 +462,6 @@ def get_request_handler(
|
||||||
if not is_body_allowed_for_status_code(response.status_code):
|
if not is_body_allowed_for_status_code(response.status_code):
|
||||||
response.body = b""
|
response.body = b""
|
||||||
response.headers.raw.extend(solved_result.response.headers.raw)
|
response.headers.raw.extend(solved_result.response.headers.raw)
|
||||||
if errors:
|
|
||||||
validation_error = RequestValidationError(
|
|
||||||
_normalize_errors(errors), body=body, endpoint_ctx=endpoint_ctx
|
|
||||||
)
|
|
||||||
raise validation_error
|
|
||||||
|
|
||||||
# Return response
|
|
||||||
assert response
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue