swoole-src
swoole-src copied to clipboard
I cannot catch errors raised by swoole before parsing HTTP request
I want to check the maximum request size so that when a user upload a file larger that package_max_length I can reject the request. But swoole does not allow me to check for this error, instead it shows warning [2025-05-07 14:16:32 *15066.2] WARNING Port_onRead_http() (ERRNO 7102): Request Entity Too Large: header-length (290) + content-length (1575386) is greater than the package_max_length(1048576) from session#1 on 0.0.0.0:8008
How Do I handle this kind of error programmatically so that I can send 413 status code to a client?.
I suggest you create
$server->on('error', function(Request $req, Response $res){
//handle payload errors and other errors gracefully
});
Thanks in advance
The error indicates that the entire packet exceeds the maximum allowed size defined by package_max_length. To resolve this, you must either:
Increase package_max_length to accommodate larger packets, or
Implement chunked/streaming transfer (resumable transmission) to handle the data in smaller segments.
If this error can be caught, the remaining business logic may lead to unpredictable/uncontrollable issues.