Improve documentation, cleanup duplicated code

This commit is contained in:
2021-03-28 15:03:42 +02:00
parent 07b018d2ab
commit cd053bc74e
5 changed files with 96 additions and 39 deletions

View File

@@ -1,8 +1,13 @@
class HTTPException(Exception):
""" Base class for HTTP exceptions """
"""
Base class for HTTP exceptions
"""
class UnhandledHTTPCode(Exception):
"""
Exception thrown if HTTP codes are not further processed.
"""
status_code: str
headers: str
cause: str
@@ -40,10 +45,12 @@ class UnsupportedEncoding(HTTPException):
self.enc_type = enc_type
self.encoding = encoding
class UnsupportedProtocol(HTTPException):
"""
Protocol is not supported
"""
def __init__(self, protocol):
self.protocol = protocol
@@ -54,7 +61,9 @@ class IncompleteResponse(HTTPException):
class HTTPServerException(HTTPException):
""" Base class for HTTP Server exceptions """
"""
Base class for HTTP Server exceptions
"""
status_code: str
message: str
body: str
@@ -66,29 +75,39 @@ class HTTPServerException(HTTPException):
class HTTPServerCloseException(HTTPServerException):
""" When thrown, the connection should be closed """
"""
When raised, the connection should be closed
"""
class BadRequest(HTTPServerCloseException):
""" Malformed HTTP request"""
"""
Malformed HTTP request
"""
status_code = 400
message = "Bad Request"
class Forbidden(HTTPServerException):
""" Request not allowed """
"""
Request not allowed
"""
status_code = 403
message = "Forbidden"
class NotFound(HTTPServerException):
""" Resource not found """
"""
Resource not found
"""
status_code = 404
message = "Not Found"
class MethodNotAllowed(HTTPServerException):
""" Method is not allowed """
"""
Method is not allowed
"""
status_code = 405
message = "Method Not Allowed"
@@ -97,37 +116,49 @@ class MethodNotAllowed(HTTPServerException):
class InternalServerError(HTTPServerCloseException):
""" Internal Server Error """
"""
Internal Server Error
"""
status_code = 500
message = "Internal Server Error"
class NotImplemented(HTTPServerException):
""" Functionality not implemented """
"""
Functionality not implemented
"""
status_code = 501
message = "Not Implemented"
class HTTPVersionNotSupported(HTTPServerCloseException):
""" The server does not support the major version HTTP used in the request message """
"""
The server does not support the major version HTTP used in the request message
"""
status_code = 505
message = "HTTP Version Not Supported"
class Conflict(HTTPServerException):
""" Conflict in the current state of the target resource """
"""
Conflict in the current state of the target resource
"""
status_code = 409
message = "Conflict"
class NotModified(HTTPServerException):
""" Requested resource was not modified """
"""
Requested resource was not modified
"""
status_code = 304
message = "Not Modified"
class InvalidRequestLine(BadRequest):
""" Request start-line is invalid """
"""
Request start-line is invalid
"""
def __init__(self, line):
self.request_line = line