Skip to content

Commit

Permalink
[WIP] add simple server for callback testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rostyq committed Oct 27, 2023
1 parent 1de4a41 commit 8ad7b28
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from http.server import HTTPServer, BaseHTTPRequestHandler


__all__ = ["run"]


class Handler(BaseHTTPRequestHandler):
def do_POST(self):
self.log_message("\"POST %s %s\"", self.path, self.protocol_version)

print(str(self.headers).strip())
content_length = int(self.headers.get("Content-Length", 0))
body = self.rfile.read(content_length).decode()

if body:
print(body)

self.send_response(204)
self.end_headers()

class Server(HTTPServer):
def __init__(self, host: str = "", port: int = 8000):
super().__init__((host, port), Handler)


if __name__ == "__main__":
with Server() as server:
host, port = server.server_address
print(f"Server listening on {host}:{port}")

try:
server.serve_forever()
except KeyboardInterrupt:
print("Server stopped")

0 comments on commit 8ad7b28

Please sign in to comment.