This commit is contained in:
2021-03-25 12:16:40 +01:00
parent 7639383782
commit edfdc94747
5 changed files with 42 additions and 11 deletions

View File

@@ -78,7 +78,8 @@ class RequestHandler:
def _has_body(self, headers):
return "transfer-encoding" in headers or "content-encoding" in headers
def _get_date(self):
@staticmethod
def _get_date():
now = datetime.now()
stamp = mktime(now.timetuple())
return format_date_time(stamp)
@@ -114,3 +115,13 @@ class RequestHandler:
logging.debug("Sending: %r", message)
self.conn.conn.sendall(message)
@staticmethod
def send_error(client: socket, code, message):
message = f"HTTP/1.1 {code} {message}\r\n"
message += RequestHandler._get_date() + "\r\n"
message += "Content-Length: 0\r\n"
message += "\r\n"
logging.debug("Sending: %r", message)
client.sendall(message.encode(FORMAT))