File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99from .request import HTTPRequest
1010from .response import HTTPResponse
1111from .route import HTTPRoute
12- from .status import HTTPStatus
12+ from .status import BAD_REQUEST_400
1313
1414class HTTPServer :
1515 """A basic socket-based HTTP server."""
@@ -107,9 +107,9 @@ def poll(self):
107107 elif request .method == HTTPMethod .GET :
108108 response = HTTPResponse (filename = request .path , root = self .root_path )
109109
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 .
111111 else :
112- response = HTTPResponse (status = HTTPStatus . INTERNAL_SERVER_ERROR )
112+ response = HTTPResponse (status = BAD_REQUEST_400 )
113113
114114 response .send (conn )
115115 except OSError as ex :
Original file line number Diff line number Diff line change 11class HTTPStatus : # pylint: disable=too-few-public-methods
22 """HTTP status codes."""
33
4- def __init__ (self , value , phrase ):
4+ def __init__ (self , code , text ):
55 """Define a status code.
66
77 :param int value: Numeric value: 200, 404, etc.
88 :param str phrase: Short phrase: "OK", "Not Found', etc.
99 """
10- self .value = value
11- self .phrase = phrase
10+ self .code = code
11+ self .text = text
1212
1313 def __repr__ (self ):
14- return f'HTTPStatus({ self .value } , "{ self .phrase } ")'
14+ return f'HTTPStatus({ self .code } , "{ self .text } ")'
1515
1616 def __str__ (self ):
17- return f"{ self .value } { self .phrase } "
17+ return f"{ self .code } { self .text } "
1818
1919
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