diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-22 22:38:08 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-22 22:38:08 +0300 |
| commit | 422e9c74b070ee82d225c0ef17193b295907e0b5 (patch) | |
| tree | 6f021abfa64ed2fb9efe64427c8cda9f073c63ee /main.py | |
| parent | 832f86f4697f314d296264bfb7b8e485a560bf55 (diff) | |
| download | httpy-422e9c74b070ee82d225c0ef17193b295907e0b5.tar.gz httpy-422e9c74b070ee82d225c0ef17193b295907e0b5.zip | |
Update things slightly
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/main.py b/main.py index 9ff95e6..dc9f97d 100644 --- a/main.py +++ b/main.py @@ -132,6 +132,7 @@ class HTTPServer: # if socket was closed -> break except OSError as e: + print(e) print("Closed.") break @@ -144,6 +145,8 @@ class HTTPServer: Handles client's connection """ + loop = asyncio.get_event_loop() + while True: # receive request from client raw_request = await self._recvall(client) @@ -211,9 +214,10 @@ class HTTPServer: # if it's an API request elif (api_version := request.path.split("/")[1]) in API_VERSIONS: data = b'' + headers = {} match api_version: case "APIv1": - status, data = await APIv1.respond(client, request) + status, data, headers = await APIv1.respond(client, request) case _: status = 400 @@ -223,7 +227,7 @@ class HTTPServer: return # send data if no error - await HTTPServer._send(client, status, data) + await HTTPServer._send(client, status, data, headers) # return after answer return @@ -279,7 +283,7 @@ class HTTPServer: byte_header += f"{key}: {value}\r\n".encode("ascii") # send response to the client - await ssl_sock_sendall( + await asyncio.get_event_loop().create_task(ssl_sock_sendall( client, b'HTTP/1.1 ' + get_response_code(response) + @@ -287,7 +291,18 @@ class HTTPServer: byte_header + # if empty, we'll just get b'\r\n\r\n' b'\r\n' + data - ) + )) + + # # send response to the client + # await ssl_sock_sendall( + # client, + # b'HTTP/1.1 ' + + # get_response_code(response) + + # b'\r\n' + + # byte_header + # if empty, we'll just get b'\r\n\r\n' + # b'\r\n' + + # data + # ) def _close_client(self, client: socket.socket): """ |