File tree Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change 9
9
from .request import HTTPRequest
10
10
from .response import HTTPResponse
11
11
from .route import HTTPRoute
12
- from .status import HTTPStatus
12
+ from .status import BAD_REQUEST_400
13
13
14
14
class HTTPServer :
15
15
"""A basic socket-based HTTP server."""
@@ -107,9 +107,9 @@ def poll(self):
107
107
elif request .method == HTTPMethod .GET :
108
108
response = HTTPResponse (filename = request .path , root = self .root_path )
109
109
110
- # If no handler exists and request method is not GET, return 500 Internal Server Error .
110
+ # If no handler exists and request method is not GET, return 400 Bad Request .
111
111
else :
112
- response = HTTPResponse (status = HTTPStatus . INTERNAL_SERVER_ERROR )
112
+ response = HTTPResponse (status = BAD_REQUEST_400 )
113
113
114
114
response .send (conn )
115
115
except OSError as ex :
Original file line number Diff line number Diff line change 1
1
class HTTPStatus : # pylint: disable=too-few-public-methods
2
2
"""HTTP status codes."""
3
3
4
- def __init__ (self , value , phrase ):
4
+ def __init__ (self , code , text ):
5
5
"""Define a status code.
6
6
7
7
:param int value: Numeric value: 200, 404, etc.
8
8
:param str phrase: Short phrase: "OK", "Not Found', etc.
9
9
"""
10
- self .value = value
11
- self .phrase = phrase
10
+ self .code = code
11
+ self .text = text
12
12
13
13
def __repr__ (self ):
14
- return f'HTTPStatus({ self .value } , "{ self .phrase } ")'
14
+ return f'HTTPStatus({ self .code } , "{ self .text } ")'
15
15
16
16
def __str__ (self ):
17
- return f"{ self .value } { self .phrase } "
17
+ return f"{ self .code } { self .text } "
18
18
19
19
20
- HTTPStatus .NOT_FOUND = HTTPStatus (404 , "Not Found" )
21
- """404 Not Found"""
22
- HTTPStatus .OK = HTTPStatus (200 , "OK" ) # pylint: disable=invalid-name
23
- """200 OK"""
24
- HTTPStatus .INTERNAL_SERVER_ERROR = HTTPStatus (500 , "Internal Server Error" )
25
- """500 Internal Server Error"""
20
+ OK_200 = HTTPStatus (200 , "OK" )
21
+ BAD_REQUEST_400 = HTTPStatus (400 , "Bad Request" )
22
+ NOT_FOUND_404 = HTTPStatus (404 , "Not Found" )
23
+ INTERNAL_SERVER_ERROR_500 = HTTPStatus (500 , "Internal Server Error" )
You can’t perform that action at this time.
0 commit comments