From b4d6f0275b4be876c4055b86349b7a45fb4e88a2 Mon Sep 17 00:00:00 2001 From: Yax <1949284+kianby@users.noreply.github.com> Date: Fri, 19 Jan 2024 19:12:16 +0100 Subject: [PATCH] Add DELETE / PUT to HTTP debug server --- private_dot_local/bin/pyserver.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/private_dot_local/bin/pyserver.py b/private_dot_local/bin/pyserver.py index efb5553..a613bae 100644 --- a/private_dot_local/bin/pyserver.py +++ b/private_dot_local/bin/pyserver.py @@ -23,10 +23,22 @@ class S(BaseHTTPRequestHandler): post_data = self.rfile.read(content_length) # <--- Gets the data itself logging.info("POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n", str(self.path), str(self.headers), post_data.decode('utf-8')) - self._set_response() self.wfile.write("POST request for {}".format(self.path).encode('utf-8')) + def do_PUT(self): + content_length = int(self.headers['Content-Length']) # <--- Gets the size of data + post_data = self.rfile.read(content_length) # <--- Gets the data itself + logging.info("PUT request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n", + str(self.path), str(self.headers), post_data.decode('utf-8')) + self._set_response() + self.wfile.write("PUT request for {}".format(self.path).encode('utf-8')) + + def do_DELETE(self): + logging.info("DELETE request,\nPath: %s\nHeaders:\n%s\n", str(self.path), str(self.headers)) + self._set_response() + self.wfile.write("DELETE request for {}".format(self.path).encode('utf-8')) + def run(server_class=HTTPServer, handler_class=S, port=8080): logging.basicConfig(level=logging.INFO) fh = logging.FileHandler('/tmp/pyserver.log')