ClickHouse/tests/integration/test_storage_s3/s3_mocks/echo.py

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

32 lines
943 B
Python
Raw Normal View History

import http.server
import sys
class RequestHandler(http.server.BaseHTTPRequestHandler):
2022-11-28 21:15:41 +00:00
def get_response(self):
if self.path.startswith("/get-my-path/"):
2022-11-28 21:15:41 +00:00
return b"/" + self.path.split("/", maxsplit=2)[2].encode()
elif self.path == "/":
2022-11-28 21:15:41 +00:00
return b"OK"
return None
def do_HEAD(self):
if self.path.startswith("/get-my-path/") or self.path == "/":
self.send_response(200)
self.send_header("Content-Type", "text/plain")
2022-11-28 21:15:41 +00:00
self.send_header("Content-Length", len(self.get_response()))
self.end_headers()
else:
self.send_response(404)
self.send_header("Content-Type", "text/plain")
self.end_headers()
def do_GET(self):
self.do_HEAD()
2022-11-28 21:15:41 +00:00
self.wfile.write(self.get_response())
httpd = http.server.HTTPServer(("0.0.0.0", int(sys.argv[1])), RequestHandler)
httpd.serve_forever()