From 3fbff8ecc44d5710d00d41513dd4c54b15761f28 Mon Sep 17 00:00:00 2001 From: ashkankzme Date: Wed, 24 Jul 2024 10:24:18 -0700 Subject: [PATCH 1/4] adding a callback server for local testing of presto --- extra/__init__.py | 0 extra/callback_server.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 extra/__init__.py create mode 100644 extra/callback_server.py diff --git a/extra/__init__.py b/extra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/extra/callback_server.py b/extra/callback_server.py new file mode 100644 index 0000000..2eb768f --- /dev/null +++ b/extra/callback_server.py @@ -0,0 +1,30 @@ +from http.server import HTTPServer, BaseHTTPRequestHandler +import sys + + +class RequestHandler(BaseHTTPRequestHandler): + def do_POST(self): + content_length = int(self.headers['Content-Length']) + post_data = self.rfile.read(content_length) + + print("Received POST request:") + print(post_data.decode('utf-8')) + + self.send_response(200) + self.send_header('Content-type', 'text/plain') + self.end_headers() + self.wfile.write(b"{\"message\": \"Message Received\"}") + + +def run_server(port=9888): + server_address = ('', port) + httpd = HTTPServer(server_address, RequestHandler) + print(f"Server running on port {port}") + httpd.serve_forever() + + +if __name__ == '__main__': + port = 9888 + if len(sys.argv) > 1: + port = int(sys.argv[1]) + run_server(port) From c2916f32ae2cd681d66716802e61d30eb9b4895e Mon Sep 17 00:00:00 2001 From: Ashkan Kazemi Date: Mon, 29 Jul 2024 09:26:22 -0700 Subject: [PATCH 2/4] Delete extra/__init__.py unnecessary file removed --- extra/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 extra/__init__.py diff --git a/extra/__init__.py b/extra/__init__.py deleted file mode 100644 index e69de29..0000000 From a5f891ba2bfe2d5fc8a1a2f00242ed9c8ab058a9 Mon Sep 17 00:00:00 2001 From: ashkankzme Date: Mon, 29 Jul 2024 11:44:20 -0700 Subject: [PATCH 3/4] addrressing PR comments --- extra/callback_server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extra/callback_server.py b/extra/callback_server.py index 2eb768f..e8c6765 100644 --- a/extra/callback_server.py +++ b/extra/callback_server.py @@ -1,5 +1,7 @@ from http.server import HTTPServer, BaseHTTPRequestHandler -import sys +import sys, os + +DEFAULT_PORT = os.getenv('LOCAL_CALLBACK_PORT', 9888) class RequestHandler(BaseHTTPRequestHandler): @@ -16,7 +18,7 @@ def do_POST(self): self.wfile.write(b"{\"message\": \"Message Received\"}") -def run_server(port=9888): +def run_server(port=DEFAULT_PORT): server_address = ('', port) httpd = HTTPServer(server_address, RequestHandler) print(f"Server running on port {port}") @@ -24,7 +26,7 @@ def run_server(port=9888): if __name__ == '__main__': - port = 9888 + port = DEFAULT_PORT if len(sys.argv) > 1: port = int(sys.argv[1]) run_server(port) From 29c45108e211a4a3062f3f99d675cd2c10132e45 Mon Sep 17 00:00:00 2001 From: ashkankzme Date: Mon, 29 Jul 2024 11:50:44 -0700 Subject: [PATCH 4/4] fixing a small bug (casting port value into int) --- extra/callback_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/callback_server.py b/extra/callback_server.py index e8c6765..1a2302c 100644 --- a/extra/callback_server.py +++ b/extra/callback_server.py @@ -1,7 +1,7 @@ from http.server import HTTPServer, BaseHTTPRequestHandler import sys, os -DEFAULT_PORT = os.getenv('LOCAL_CALLBACK_PORT', 9888) +DEFAULT_PORT = int(os.getenv('LOCAL_CALLBACK_PORT', 9888)) class RequestHandler(BaseHTTPRequestHandler):