-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(routing)!: Refactor routes and route handlers (#3386)
* remove handler names * Remove option handler creation from HTTPRoute * Remove methods attribute from BaseRoute * Move kwargs model to handlers and creation to on_registration * Store kwargs model on handlers instead of routes * Simplify HTTPRoute route_handler_map creation * Simplify Router.route_handler_method_map * Relax typing of HTTPRoute * Move handling logic to route handlers * Remove scope_type * Don't pass route to HTTPRouteHandler during handling * Don't pass scope to handle methods * Resolve and establish connections in routes; Only pass connections to handlers --------- Co-authored-by: Jacob Coffee <jacob@z7x.org> Co-authored-by: Peter Schutt <peter.github@proton.me>
- Loading branch information
1 parent
f7a8af3
commit ccbf930
Showing
30 changed files
with
431 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Iterable | ||
|
||
from litestar.enums import HttpMethod, MediaType | ||
from litestar.handlers import HTTPRouteHandler | ||
from litestar.response import Response | ||
from litestar.status_codes import HTTP_204_NO_CONTENT | ||
|
||
if TYPE_CHECKING: | ||
from litestar.types import Method | ||
|
||
|
||
def create_options_handler(path: str, allow_methods: Iterable[Method]) -> HTTPRouteHandler: | ||
"""Args: | ||
path: The route path | ||
Returns: | ||
An HTTP route handler for OPTIONS requests. | ||
""" | ||
|
||
def options_handler() -> Response: | ||
"""Handler function for OPTIONS requests. | ||
Returns: | ||
Response | ||
""" | ||
return Response( | ||
content=None, | ||
status_code=HTTP_204_NO_CONTENT, | ||
headers={"Allow": ", ".join(sorted(allow_methods))}, # pyright: ignore | ||
media_type=MediaType.TEXT, | ||
) | ||
|
||
return HTTPRouteHandler( | ||
path=path, | ||
http_method=[HttpMethod.OPTIONS], | ||
include_in_schema=False, | ||
sync_to_thread=False, | ||
)(options_handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.