Skip to content

Commit c95290f

Browse files
committed
Replaced route_handlers dict with _HTTPRoutes object in HTTPServer
1 parent 8e2967b commit c95290f

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

adafruit_httpserver/server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .methods import HTTPMethod
2020
from .request import HTTPRequest
2121
from .response import HTTPResponse
22-
from .route import _HTTPRoute
22+
from .route import _HTTPRoutes, _HTTPRoute
2323
from .status import CommonHTTPStatus
2424

2525

@@ -34,12 +34,12 @@ def __init__(self, socket_source: Protocol) -> None:
3434
"""
3535
self._buffer = bytearray(1024)
3636
self._timeout = 1
37-
self.route_handlers = {}
37+
self.routes = _HTTPRoutes()
3838
self._socket_source = socket_source
3939
self._sock = None
4040
self.root_path = "/"
4141

42-
def route(self, path: str, method: HTTPMethod = HTTPMethod.GET):
42+
def route(self, path: str, method: HTTPMethod = HTTPMethod.GET) -> Callable:
4343
"""
4444
Decorator used to add a route.
4545
@@ -54,7 +54,7 @@ def route_func(request):
5454
"""
5555

5656
def route_decorator(func: Callable) -> Callable:
57-
self.route_handlers[_HTTPRoute(path, method)] = func
57+
self.routes.add(_HTTPRoute(path, method), func)
5858
return func
5959

6060
return route_decorator
@@ -154,8 +154,8 @@ def poll(self):
154154
conn, received_body_bytes, content_length
155155
)
156156

157-
handler = self.route_handlers.get(
158-
_HTTPRoute(request.path, request.method), None
157+
handler = self.routes.find_handler(
158+
_HTTPRoute(request.path, request.method)
159159
)
160160

161161
# If a handler for route exists and is callable, call it.

0 commit comments

Comments
 (0)