-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from meedan/CV2-4978
CV2-4978: Local callback server for receiving presto callback responses
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |