Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 167
Open
Labels
Description
When a request is cancelled, the promise seems to not be cancelled.
<?phprequire__DIR__ . '/../vendor/autoload.php'; usefunctionReact\Async\async; usefunctionReact\Async\delay; usefunctionReact\Promise\resolve; usePsr\Http\Message\ServerRequestInterface; useReact\Http\Message\Response; $http = newReact\Http\HttpServer( function (ServerRequestInterface$request, callable$next){$withHeaders = [ 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => '*', 'Access-Control-Allow-Headers' => '*', 'Access-Control-Expose-Headers' => '*', ]; if ($request->getMethod() == 'OPTIONS'){returnnewResponse(200, $withHeaders, 'OK')} returnresolve($next($request))->then( function ($response) use ($withHeaders){foreach ($withHeadersas$key => $value){if (!$response->hasHeader($key)){$response = $response->withHeader($key, $value)} } return$response} )}, function (Psr\Http\Message\ServerRequestInterface$request){returnasync(function (){echo"hello world 1\n"; delay(3); echo"hello world 2\n"; returnReact\Http\Message\Response::plaintext( "Hello World!\n" )->withHeader('Access-Control-Allow-Origin', '*') ->withHeader('Access-Control-Allow-Methods', '*') ->withHeader('Access-Control-Allow-Headers', '*') ->withHeader('Access-Control-Expose-Headers', '*')})()} ); $socket = newReact\Socket\SocketServer(getenv('LISTEN') ?: '0.0.0.0:8070'); $http->listen($socket); echo"Server running at http://127.0.0.1:8070" . PHP_EOL;front Cancel request after 1 seconds.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> const controller = new AbortController(); const signal = controller.signal; setTimeout(() =>{controller.abort()}, 1000); fetch('http://192.168.1.9:8070',{signal, method: 'post', headers:{'Content-Type': 'application/json' }, body: JSON.stringify({'hello':'world' }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error =>{if (error.name === 'AbortError'){console.log('请求已取消')} else{console.error('请求失败:', error)} }); </script> </body> </html> After the cancellation of the 1 second, the backend also displayed "hello world 2".
when modify the https://github.com/reactphp/http/blob/3.x/src/Middleware/RequestBodyBufferMiddleware.php ,it work for me