diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-27 15:44:19 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-27 15:44:19 +0300 |
| commit | fdda4950d518e4ddae8a548f8ff6c8b0d4cba41a (patch) | |
| tree | 8471fb2b1f657b848507425d74b12bbb8ac018f2 /main.py | |
| parent | 3263cfdee15391995532545df84b8e4144684879 (diff) | |
| download | httpy-fdda4950d518e4ddae8a548f8ff6c8b0d4cba41a.tar.gz httpy-fdda4950d518e4ddae8a548f8ff6c8b0d4cba41a.zip | |
wut?
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/main.py b/main.py index 9098210..408fbe4 100644 --- a/main.py +++ b/main.py @@ -91,7 +91,16 @@ class HTTPServer: # listen and respond handler while not self.stop_event.is_set(): # accept new client - client = self._accept() + try: + client = self._accept() + except ssl.SSLError: + continue + except OSError as e: + logging.info(f"Client dropped due to: {e}") + continue + except Exception: + logging.warning(f"ignoring exception:\n{traceback.format_exc()}") + continue if client is None: continue @@ -109,12 +118,13 @@ class HTTPServer: :param client: client ssl socket """ + client.setblocking(True) # in ssl it's the default, in plain sockets it's not self.semaphore.acquire() try: request = self._recv_request(client) if request is not None: self._client_request_handler(client, request) - except ssl.SSLEOFError: + except ssl.SSLError: pass except OSError as e: logging.info(f"request dropped due to: {e}") @@ -152,8 +162,6 @@ class HTTPServer: # send message client.sendall(message) for packet in response.get_data_stream(): - if packet is None: - break client.sendall(packet) # check for stop event @@ -217,14 +225,6 @@ class HTTPServer: return self.sock.accept()[0] except BlockingIOError: time.sleep(0.005) - except ssl.SSLEOFError: - break - except OSError as e: - logging.info(f"Client dropped due to: {e}") - break - except Exception: - logging.warning(f"ignoring exception:\n{traceback.format_exc()}") - break return None def fetch_file_headers(self, path: str) -> dict[str, Any] | None: @@ -247,8 +247,9 @@ class HTTPServer: if path in self.path_map: with open(self.path_map[path]["path"], "rb") as file: - while (msg := file.read(BUFFER_LENGTH)): + while (msg := file.read(BUFFER_LENGTH)) is not None: yield msg + raise StopIteration yield None |