Skip to content

Commit 4224ac8

Browse files
committed
Replaced CommonHTTPStatus with direct values
1 parent d4a8a8d commit 4224ac8

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

adafruit_httpserver/response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from .mime_type import MIMEType
2727
from .request import Request
28-
from .status import Status, CommonHTTPStatus
28+
from .status import Status, OK_200
2929
from .headers import Headers
3030

3131

@@ -103,7 +103,7 @@ def route_func(request):
103103
def __init__( # pylint: disable=too-many-arguments
104104
self,
105105
request: Request,
106-
status: Union[Status, Tuple[int, str]] = CommonHTTPStatus.OK_200,
106+
status: Union[Status, Tuple[int, str]] = OK_200,
107107
headers: Union[Headers, Dict[str, str]] = None,
108108
content_type: str = None,
109109
http_version: str = "HTTP/1.1",

adafruit_httpserver/server.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .request import Request
2222
from .response import Response
2323
from .route import _Routes, _Route
24-
from .status import CommonHTTPStatus
24+
from .status import BAD_REQUEST_400, UNAUTHORIZED_401, FORBIDDEN_403, NOT_FOUND_404
2525

2626

2727
class Server:
@@ -177,26 +177,20 @@ def poll(self):
177177
head_only=(request.method == HEAD),
178178
)
179179
else:
180-
HTTPResponse(
181-
request, status=CommonHTTPStatus.BAD_REQUEST_400
182-
).send()
180+
Response(request, status=BAD_REQUEST_400).send()
183181

184182
except AuthenticationError:
185183
Response(
186184
request,
187-
status=CommonHTTPStatus.UNAUTHORIZED_401,
185+
status=UNAUTHORIZED_401,
188186
headers={"WWW-Authenticate": 'Basic charset="UTF-8"'},
189187
).send()
190188

191189
except InvalidPathError as error:
192-
Response(request, status=CommonHTTPStatus.FORBIDDEN_403).send(
193-
str(error)
194-
)
190+
Response(request, status=FORBIDDEN_403).send(str(error))
195191

196192
except FileNotExistsError as error:
197-
Response(request, status=CommonHTTPStatus.NOT_FOUND_404).send(
198-
str(error)
199-
)
193+
Response(request, status=NOT_FOUND_404).send(str(error))
200194

201195
except OSError as error:
202196
# Handle EAGAIN and ECONNRESET

adafruit_httpserver/status.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,38 @@ def __eq__(self, other: "Status"):
3131
return self.code == other.code and self.text == other.text
3232

3333

34-
class CommonHTTPStatus(HTTPStatus): # pylint: disable=too-few-public-methods
35-
"""Common HTTP status codes."""
34+
OK_200 = Status(200, "OK")
35+
"""200 OK"""
3636

37-
OK_200 = HTTPStatus(200, "OK")
38-
"""200 OK"""
37+
NO_CONTENT_204 = Status(204, "No Content")
38+
"""204 No Content"""
3939

40-
BAD_REQUEST_400 = HTTPStatus(400, "Bad Request")
41-
"""400 Bad Request"""
40+
TEMPORARY_REDIRECT_307 = Status(307, "Temporary Redirect")
41+
"""307 Temporary Redirect"""
4242

43-
UNAUTHORIZED_401 = HTTPStatus(401, "Unauthorized")
44-
"""401 Unauthorized"""
43+
PERMANENT_REDIRECT_308 = Status(308, "Permanent Redirect")
44+
"""308 Permanent Redirect"""
4545

46-
FORBIDDEN_403 = HTTPStatus(403, "Forbidden")
47-
"""403 Forbidden"""
46+
BAD_REQUEST_400 = Status(400, "Bad Request")
47+
"""400 Bad Request"""
4848

49-
NOT_FOUND_404 = HTTPStatus(404, "Not Found")
50-
"""404 Not Found"""
49+
UNAUTHORIZED_401 = Status(401, "Unauthorized")
50+
"""401 Unauthorized"""
5151

52-
INTERNAL_SERVER_ERROR_500 = HTTPStatus(500, "Internal Server Error")
53-
"""500 Internal Server Error"""
52+
FORBIDDEN_403 = Status(403, "Forbidden")
53+
"""403 Forbidden"""
54+
55+
NOT_FOUND_404 = Status(404, "Not Found")
56+
"""404 Not Found"""
57+
58+
METHOD_NOT_ALLOWED_405 = Status(405, "Method Not Allowed")
59+
"""405 Method Not Allowed"""
60+
61+
INTERNAL_SERVER_ERROR_500 = Status(500, "Internal Server Error")
62+
"""500 Internal Server Error"""
63+
64+
NOT_IMPLEMENTED_501 = Status(501, "Not Implemented")
65+
"""501 Not Implemented"""
66+
67+
SERVICE_UNAVAILABLE_503 = Status(503, "Service Unavailable")
68+
"""503 Service Unavailable"""

0 commit comments

Comments
 (0)