Skip to content

Commit 4101db8

Browse files
committed
Added HTTPMethod enum
1 parent 6892a93 commit 4101db8

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

adafruit_httpserver/methods.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
class HTTPMethod:
3+
"""HTTP method."""
4+
5+
GET = "GET"
6+
POST = "POST"
7+
PUT = "PUT"
8+
DELETE = "DELETE"
9+
PATCH = "PATCH"
10+
HEAD = "HEAD"
11+
OPTIONS = "OPTIONS"
12+
TRACE = "TRACE"
13+
CONNECT = "CONNECT"

adafruit_httpserver/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from errno import EAGAIN, ECONNRESET
77

8+
from .methods import HTTPMethod
89
from .request import _HTTPRequest
910
from .response import HTTPResponse
1011
from .status import HTTPStatus
@@ -26,11 +27,11 @@ def __init__(self, socket_source: Any) -> None:
2627
self._sock = None
2728
self.root_path = "/"
2829

29-
def route(self, path: str, method: str = "GET"):
30+
def route(self, path: str, method: HTTPMethod = HTTPMethod.GET):
3031
"""Decorator used to add a route.
3132
3233
:param str path: filename path
33-
:param str method: HTTP method: "GET", "POST", etc.
34+
:param HTTPMethod method: HTTP method: HTTPMethod.GET, HTTPMethod.POST, etc.
3435
3536
Example::
3637
@@ -99,7 +100,7 @@ def poll(self):
99100
route = self.routes.get(request, None)
100101
if route:
101102
response = route(request)
102-
elif request.method == "GET":
103+
elif request.method == HTTPMethod.GET:
103104
response = HTTPResponse(filename=request.path, root=self.root_path)
104105
else:
105106
response = HTTPResponse(status=HTTPStatus.INTERNAL_SERVER_ERROR)

0 commit comments

Comments
 (0)