Skip to content

Commit

Permalink
Add status code to ResponseContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Jan 9, 2025
1 parent 042d4c6 commit 6ac2c9f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/en/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hide:
- `name` parameter to StaticFiles config allowing to reverse lookup internally.
- Support for Python 3.13
- Support for `redirect_slashes` in the Include.
- `status_code` to ResponseContainer to be parameter detectable.

### Changed

Expand Down
12 changes: 12 additions & 0 deletions esmerald/datastructures/redirect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import TYPE_CHECKING, Any, Dict, Type, Union

from lilya import status
from lilya.responses import RedirectResponse # noqa
from typing_extensions import Annotated, Doc

Expand All @@ -22,6 +23,17 @@ class Redirect(ResponseContainer[RedirectResponse]):
"""
),
]
status_code: Annotated[
int,
Doc(
"""
The status code of the response.
This should be in format of `int`.
Example: `301`.
"""
),
] = status.HTTP_307_TEMPORARY_REDIRECT

def to_response(
self,
Expand Down
2 changes: 1 addition & 1 deletion esmerald/routing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async def response_content(
response: Response = data.to_response(
app=app,
headers=_headers,
status_code=self.status_code,
status_code=data.status_code or self.status_code,
media_type=media_type,
)
for cookie in _cookies:
Expand Down
2 changes: 1 addition & 1 deletion esmerald/routing/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2824,7 +2824,7 @@ async def another(request: Request) -> str:
routes or not.
"""
),
] = None,
] = True,
) -> None:
self.path = path
if not path:
Expand Down

0 comments on commit 6ac2c9f

Please sign in to comment.