|
@@ -1,48 +1,48 @@
|
|
|
-from http.server import HTTPServer
|
|
|
-from http.server import BaseHTTPRequestHandler
|
|
|
-
|
|
|
-class HttpGetHandler(BaseHTTPRequestHandler):
|
|
|
- def do_GET(self):
|
|
|
- try:
|
|
|
- if self.path.endswith("/"):
|
|
|
- self.send_response(200)
|
|
|
-
|
|
|
- self.send_header("Content-type","text/html")
|
|
|
- self.end_headers()
|
|
|
-
|
|
|
- http_text = """ <html><head><meta charset = 'utf-8'>
|
|
|
- <title>Простой HTTP-сервер.</title></head>
|
|
|
- <body>Код 200.</body></html> """
|
|
|
-
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
-
|
|
|
- if self.path.endswith("/info"):
|
|
|
- self.send_response(200)
|
|
|
-
|
|
|
- self.send_header("Content-type", "text/html")
|
|
|
- self.end_headers()
|
|
|
-
|
|
|
- http_text = """ <html><head><meta charset = 'utf-8'>
|
|
|
- <title>Простой HTTP-сервер.</title></head>
|
|
|
- <body>Кардаполов Владислав Сергеевич 703 группа.</body></html> """
|
|
|
-
|
|
|
- self.wfile.write(http_text.encode())
|
|
|
-
|
|
|
- except IOError:
|
|
|
- self.send_error(400,f"File not found{self.path}")
|
|
|
-
|
|
|
-
|
|
|
-def main(server_class=HTTPServer, handler_class=HttpGetHandler):
|
|
|
- server_address = ('localhost', 8000)
|
|
|
- httpd = server_class(server_address, handler_class)
|
|
|
- try:
|
|
|
- print("СвЯзЬ УсТАнОвЛЕн")
|
|
|
- httpd.serve_forever()
|
|
|
-
|
|
|
- except KeyboardInterrupt:
|
|
|
- httpd.serber_close()
|
|
|
- print("СвЯзЬ НЕ УсТАнОвЛеН")
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- main()
|
|
|
+from http.server import HTTPServer
|
|
|
+from http.server import BaseHTTPRequestHandler
|
|
|
+
|
|
|
+class HttpGetHandler(BaseHTTPRequestHandler):
|
|
|
+ def do_GET(self):
|
|
|
+ try:
|
|
|
+ if self.path.endswith("/"):
|
|
|
+ self.send_response(200)
|
|
|
+
|
|
|
+ self.send_header("Content-type","text/html")
|
|
|
+ self.end_headers()
|
|
|
+
|
|
|
+ http_text = """ <html><head><meta charset = 'utf-8'>
|
|
|
+ <title>Простой HTTP-сервер.</title></head>
|
|
|
+ <body>Код 200.</body></html> """
|
|
|
+
|
|
|
+ self.wfile.write(http_text.encode())
|
|
|
+
|
|
|
+ if self.path.endswith("/info"):
|
|
|
+ self.send_response(200)
|
|
|
+
|
|
|
+ self.send_header("Content-type", "text/html")
|
|
|
+ self.end_headers()
|
|
|
+
|
|
|
+ http_text = """ <html><head><meta charset = 'utf-8'>
|
|
|
+ <title>Простой HTTP-сервер.</title></head>
|
|
|
+ <body>Кардаполов Владислав Сергеевич 703 группа.</body></html> """
|
|
|
+
|
|
|
+ self.wfile.write(http_text.encode())
|
|
|
+
|
|
|
+ except IOError:
|
|
|
+ self.send_error(400,f"File not found{self.path}")
|
|
|
+
|
|
|
+
|
|
|
+def main(server_class=HTTPServer, handler_class=HttpGetHandler):
|
|
|
+ server_address = ('localhost', 8000)
|
|
|
+ httpd = server_class(server_address, handler_class)
|
|
|
+ try:
|
|
|
+ print("СвЯзЬ УсТАнОвЛЕн")
|
|
|
+ httpd.serve_forever()
|
|
|
+
|
|
|
+ except KeyboardInterrupt:
|
|
|
+ httpd.serber_close()
|
|
|
+ print("СвЯзЬ НЕ УсТАнОвЛеН")
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == '__main__':
|
|
|
+ main()
|