🎨 clean up a bit
This commit is contained in:
parent
ecf11bcefe
commit
dc5c57d835
@ -70,4 +70,4 @@ def form(request):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# can also add routes like this:
|
# can also add routes like this:
|
||||||
# app.add_route("/", index)
|
# app.add_route("/", index)
|
||||||
app.start()
|
app.start(blocking=True)
|
||||||
|
@ -350,8 +350,6 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|||||||
request.content = content
|
request.content = content
|
||||||
self.handle_request(request)
|
self.handle_request(request)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_route(self, path) -> tuple[Callable, dict[str, Any], list[str]]:
|
def get_route(self, path) -> tuple[Callable, dict[str, Any], list[str]]:
|
||||||
for option in self._routes.keys():
|
for option in self._routes.keys():
|
||||||
if match_data := option.match(path):
|
if match_data := option.match(path):
|
||||||
@ -444,8 +442,6 @@ class RequestHandler(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
def handle_request(self, request):
|
def handle_request(self, request):
|
||||||
|
|
||||||
request.url = urlparse.urlparse(request.path)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handler, additional_args, allowed_methods = self.get_route(request.url.path)
|
handler, additional_args, allowed_methods = self.get_route(request.url.path)
|
||||||
except NotFound:
|
except NotFound:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
|
||||||
class Request:
|
class Request:
|
||||||
@ -9,7 +10,6 @@ class Request:
|
|||||||
method=None,
|
method=None,
|
||||||
headers=None,
|
headers=None,
|
||||||
path=None,
|
path=None,
|
||||||
url=None,
|
|
||||||
query_params=None,
|
query_params=None,
|
||||||
server=None
|
server=None
|
||||||
):
|
):
|
||||||
@ -18,7 +18,7 @@ class Request:
|
|||||||
self.method: str = method
|
self.method: str = method
|
||||||
self.headers: dict[str] = headers
|
self.headers: dict[str] = headers
|
||||||
self.path: str = path
|
self.path: str = path
|
||||||
self.url = url
|
self.url = urlparse(path)
|
||||||
self.query_params = query_params
|
self.query_params = query_params
|
||||||
self.server = server
|
self.server = server
|
||||||
self.GET = {}
|
self.GET = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user