Improve documentation
This commit is contained in:
@@ -6,7 +6,7 @@ from urllib.parse import ParseResultBytes, ParseResult
|
||||
from httplib import parser
|
||||
from httplib.exceptions import MethodNotAllowed, BadRequest, UnsupportedEncoding, NotImplemented, NotFound, \
|
||||
HTTPVersionNotSupported
|
||||
from httplib.httpsocket import HTTPSocket, FORMAT
|
||||
from httplib.httpsocket import FORMAT
|
||||
from httplib.message import RequestMessage as Message
|
||||
from httplib.retriever import Retriever, PreambleRetriever
|
||||
from server import command
|
||||
@@ -23,12 +23,15 @@ class RequestHandler:
|
||||
messages, parse, verify them and send a respond.
|
||||
"""
|
||||
|
||||
conn: HTTPSocket
|
||||
conn: ServerSocket
|
||||
|
||||
def __init__(self, conn: socket, host):
|
||||
self.conn = ServerSocket(conn, host)
|
||||
|
||||
def listen(self):
|
||||
"""
|
||||
Listen to incoming messages and process them.
|
||||
"""
|
||||
|
||||
retriever = PreambleRetriever(self.conn)
|
||||
|
||||
@@ -42,6 +45,12 @@ class RequestHandler:
|
||||
self._handle_message(retriever, line)
|
||||
|
||||
def _handle_message(self, retriever, line):
|
||||
"""
|
||||
Retrieves and processes the request message.
|
||||
|
||||
@param retriever: the retriever instance to retrieve the lines.
|
||||
@param line: the first received line.
|
||||
"""
|
||||
lines = retriever.retrieve()
|
||||
|
||||
# Parse the request-line and headers
|
||||
@@ -80,7 +89,8 @@ class RequestHandler:
|
||||
|
||||
def _check_request_line(self, method: str, target: Union[ParseResultBytes, ParseResult], version):
|
||||
"""
|
||||
Checks if the request-line is valid. Throws an appriopriate exception if not.
|
||||
Checks if the request-line is valid. Throws an appropriate exception if not.
|
||||
|
||||
@param method: HTTP request method
|
||||
@param target: The request target
|
||||
@param version: The HTTP version
|
||||
@@ -124,6 +134,7 @@ class RequestHandler:
|
||||
def _has_body(self, headers):
|
||||
"""
|
||||
Check if the headers notify the existing of a message body.
|
||||
|
||||
@param headers: the headers to check
|
||||
@return: True if the message has a body. False otherwise.
|
||||
"""
|
||||
@@ -138,6 +149,14 @@ class RequestHandler:
|
||||
|
||||
@staticmethod
|
||||
def send_error(client: socket, code, message):
|
||||
"""
|
||||
Send and HTTP error response to the client
|
||||
|
||||
@param client: the client to send the response to
|
||||
@param code: the HTTP status code
|
||||
@param message: the status code message
|
||||
"""
|
||||
|
||||
message = f"HTTP/1.1 {code} {message}\r\n"
|
||||
message += parser.get_date() + "\r\n"
|
||||
message += "Content-Length: 0\r\n"
|
||||
|
Reference in New Issue
Block a user