2021-05-04 06:25:33 +00:00
|
|
|
import http.server
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
class RequestHandler(http.server.BaseHTTPRequestHandler):
|
2022-11-28 21:15:41 +00:00
|
|
|
def get_response(self):
|
2021-05-04 06:25:33 +00:00
|
|
|
if self.path.startswith("/get-my-path/"):
|
2022-11-28 21:15:41 +00:00
|
|
|
return b"/" + self.path.split("/", maxsplit=2)[2].encode()
|
2021-05-04 06:25:33 +00:00
|
|
|
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 == "/":
|
2021-05-04 06:25:33 +00:00
|
|
|
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()))
|
2021-05-04 06:25:33 +00:00
|
|
|
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())
|
2021-05-04 06:25:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
httpd = http.server.HTTPServer(("0.0.0.0", int(sys.argv[1])), RequestHandler)
|
|
|
|
httpd.serve_forever()
|