Kaynağa Gözat

first commit

Смаков Роман Маратович 2 yıl önce
ebeveyn
işleme
c787097791
2 değiştirilmiş dosya ile 54 ekleme ve 0 silme
  1. 3 0
      .gitignore
  2. 51 0
      testlp1.py

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.idea/
+
+main.py

+ 51 - 0
testlp1.py

@@ -0,0 +1,51 @@
+from http.server import HTTPServer, 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>Смаков Роман Маратович,студент 701(3) группы.</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()
+
+
+