2022-03-09 13:45:36 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-09-08 13:22:34 +00:00
|
|
|
import json
|
2022-03-09 13:45:36 +00:00
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
2021-09-08 13:22:34 +00:00
|
|
|
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
|
|
|
|
|
|
class RequestHandler(BaseHTTPRequestHandler):
|
|
|
|
def do_POST(self):
|
|
|
|
request_path = self.path
|
|
|
|
request_body = self.rfile.read(int(self.headers['Content-Length']))
|
2021-09-09 17:12:44 +00:00
|
|
|
request_body = json.loads(request_body.decode())
|
2021-09-08 13:22:34 +00:00
|
|
|
log = {
|
|
|
|
"path": request_path,
|
2022-03-09 13:45:36 +00:00
|
|
|
"status": 200,
|
2021-09-08 13:22:34 +00:00
|
|
|
"request_body": request_body,
|
|
|
|
}
|
|
|
|
print(json.dumps(log))
|
|
|
|
self.send_response(200)
|
|
|
|
self.send_header('Content-type','application/json')
|
|
|
|
self.end_headers()
|
|
|
|
self.wfile.write(json.dumps({}).encode())
|
2022-04-19 17:12:23 +00:00
|
|
|
self.wfile.flush()
|
2021-09-08 13:22:34 +00:00
|
|
|
return
|
2022-03-09 13:45:36 +00:00
|
|
|
|
2021-09-08 13:22:34 +00:00
|
|
|
def log_message(self, format, *args):
|
|
|
|
return
|
|
|
|
|
2022-03-09 13:45:36 +00:00
|
|
|
def main(argv):
|
|
|
|
try:
|
|
|
|
port = int(argv[1])
|
|
|
|
except IndexError:
|
|
|
|
logging.fatal("Missing port number")
|
|
|
|
return 1
|
|
|
|
except ValueError:
|
|
|
|
logging.fatal("Invalid port number '%s'", argv[1])
|
|
|
|
return 1
|
|
|
|
server = HTTPServer(('', port), RequestHandler)
|
|
|
|
# logging.info('Listening on port %s', port)
|
|
|
|
server.serve_forever()
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2021-09-08 13:22:34 +00:00
|
|
|
if __name__ == "__main__" :
|
2022-03-09 13:45:36 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
sys.exit(main(sys.argv))
|