new: [workflow] Added simplistic webhoob listener in tools/

pull/8530/head
Sami Mokaddem 2022-07-15 11:47:44 +02:00
parent 87b92109d2
commit f6d752890a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
from pprint import pprint
hostName = "0.0.0.0"
serverPort = 27051
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
print(self.path)
self.wfile.write(bytes("<html><head><title>https://pythonbasics.org</title></head>", "utf-8"))
self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
self.wfile.write(bytes("<body>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
def do_POST(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.data_string = self.rfile.read(int(self.headers['Content-Length']))
data = json.loads(self.data_string)
pprint(data)
print()
self.wfile.write(bytes("<html><head><title>https://pythonbasics.org</title></head>", "utf-8"))
self.wfile.write(bytes("<p>Request: %s</p>" % self.path, "utf-8"))
self.wfile.write(bytes("<body>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")