ClickHouse/tests/integration/test_placement_info/metadata_servers/simple_server.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
824 B
Python
Raw Normal View History

2024-02-13 09:40:49 +00:00
import http.server
import sys
class RequestHandler(http.server.BaseHTTPRequestHandler):
def get_response(self):
if self.path == "/":
return "OK", 200
if self.path == "/latest/meta-data/placement/availability-zone":
return "ci-test-1a", 200
# Resource not found.
return 404
def do_HEAD(self):
response, code = self.get_response()
self.send_response(code)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", len(response.encode()))
self.end_headers()
return response, code
def do_GET(self):
response, _ = self.do_HEAD()
self.wfile.write(response.encode())
httpd = http.server.HTTPServer(("0.0.0.0", int(sys.argv[1])), RequestHandler)
httpd.serve_forever()