22from urllib .parse import urlparse , parse_qs
33import json
44
5+ # Class for the control message
56class ControlMessage :
67 def __init__ (self , text , number ):
78 self .text = text
@@ -10,14 +11,17 @@ def __init__(self, text, number):
1011 def __str__ (self ):
1112 return f"Text: { self .text } , Number: { self .number } "
1213
14+ # Request handler class
1315class RequestHandler (BaseHTTPRequestHandler ):
1416 def do_GET (self ):
17+ # Process GET requests
1518 self .send_response (200 )
1619 self .send_header ("Content-type" , "text/plain" )
1720 self .end_headers ()
1821 self .wfile .write (bytes ("OK: It's a GET method or URL not in \" /admin\" " , "utf-8" ))
1922
2023 def do_POST (self ):
24+ # Process POST requests
2125 if self .path .startswith ("/admin" ):
2226 content_length = int (self .headers .get ("Content-Length" , 0 ))
2327 body = self .rfile .read (content_length ).decode ("utf-8" )
@@ -26,6 +30,7 @@ def do_POST(self):
2630 number = params .get ("number" , [None ])[0 ]
2731
2832 if text is None or not number .isdigit ():
33+ # Invalid request: missing text or number
2934 self .send_response (400 )
3035 self .send_header ("Content-type" , "text/plain" )
3136 self .end_headers ()
@@ -44,9 +49,11 @@ def do_POST(self):
4449 self .end_headers ()
4550 self .wfile .write (bytes ("OK: It's a GET method or URL not in \" /admin\" " , "utf-8" ))
4651
52+ # Process the control message
4753def process_message (message ):
4854 print (f"Accepted Control message: { message } " )
4955
56+ # Start the server
5057def start_server ():
5158 host = "localhost"
5259 port = 3020
0 commit comments