Title: Update TCP HTTP server and plugin loader with enhanced security and error handling
Key features implemented: - Updated .gitignore with cleaner Python and build artifact patterns - Enhanced TcpHttpServer with improved exception handling for connection errors and better request parsing - Added detailed error event emission for OSError and other exceptions in TCP server - Improved plugin loader security with enhanced configuration file validation and error handling - Added comprehensive logging for plugin loading and dependency injection processes - Refined PL injection mechanism with stricter function name and route validation The updates provide more robust error handling in the TCP server and strengthen security measures in the plugin loader while improving overall system stability.
This commit is contained in:
@@ -133,9 +133,18 @@ class TcpHttpServer:
|
||||
|
||||
buffer = b""
|
||||
|
||||
except ConnectionResetError:
|
||||
# 客户端断开连接,正常情况
|
||||
pass
|
||||
except BrokenPipeError:
|
||||
# 管道破裂,正常情况
|
||||
pass
|
||||
except OSError as e:
|
||||
if self.event_bus:
|
||||
self.event_bus.emit(TcpEvent(type=EVENT_ERROR, client=client, context={"error": f"OSError: {e}"}))
|
||||
except Exception as e:
|
||||
if self.event_bus:
|
||||
self.event_bus.emit(TcpEvent(type=EVENT_ERROR, client=client, context={"error": str(e)}))
|
||||
self.event_bus.emit(TcpEvent(type=EVENT_ERROR, client=client, context={"error": f"{type(e).__name__}: {e}"}))
|
||||
finally:
|
||||
del self._clients[client.id]
|
||||
client.close()
|
||||
@@ -179,7 +188,12 @@ class TcpHttpServer:
|
||||
"headers": headers,
|
||||
"body": body,
|
||||
}
|
||||
except UnicodeDecodeError:
|
||||
return None
|
||||
except ValueError:
|
||||
return None
|
||||
except Exception:
|
||||
# 其他解析错误
|
||||
return None
|
||||
|
||||
def _format_response(self, response: dict) -> bytes:
|
||||
|
||||
Reference in New Issue
Block a user