Skip to content

Commit

Permalink
Merge pull request #99 from meedan/CV2-4978
Browse files Browse the repository at this point in the history
CV2-4978: Local callback server for receiving presto callback responses
  • Loading branch information
ashkankzme authored Jul 29, 2024
2 parents 589d144 + 29c4510 commit ed55ff3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions extra/callback_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from http.server import HTTPServer, BaseHTTPRequestHandler
import sys, os

DEFAULT_PORT = int(os.getenv('LOCAL_CALLBACK_PORT', 9888))


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=DEFAULT_PORT):
server_address = ('', port)
httpd = HTTPServer(server_address, RequestHandler)
print(f"Server running on port {port}")
httpd.serve_forever()


if __name__ == '__main__':
port = DEFAULT_PORT
if len(sys.argv) > 1:
port = int(sys.argv[1])
run_server(port)

0 comments on commit ed55ff3

Please sign in to comment.