When a request is cancelled, the promise seems to not be cancelled.
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Start with src/Middleware/RequestBodyBufferMiddleware.php and reproduce the delayed handler using the provided PHP server and browser AbortController example. Compare the 3.x behavior with the linked comparison, then verify that cancelling the request no longer allows the delayed handler to continue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When a request is cancelled, the promise seems to not be cancelled.
<?php
require __DIR__ . '/../vendor/autoload.php';
use function React\Async\async;
use function React\Async\delay;
use function React\Promise\resolve;
use Psr\Http\Message\ServerRequestInterface;
use React\Http\Message\Response;
$http = new React\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') {
return new Response(200, $withHeaders, 'OK');
}
return resolve($next($request))->then(
function ($response) use ($withHeaders) {
foreach ($withHeaders as $key => $value) {
if (!$response->hasHeader($key)) {
$response = $response->withHeader($key, $value);
}
}
return $response;
}
);
},
function (Psr\Http\Message\ServerRequestInterface $request) {
return async(function () {
echo "hello world 1\n";
delay(3);
echo "hello world 2\n";
return React\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 = new React\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
- Lingua principale
- PHP
- Stelle
- 781
- Fork
- 166
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di reactphp/http
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
-
Roadmap to reactphp/http v3 Apertamaintenance
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
-
new feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
help wanted new feature
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
new feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Tutte le issue di reactphp/http
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
getgrav/grav-plugin-api#45 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
RSS-Bridge/rss-bridge#5098 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
phingofficial/phing#2025 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
silverstripe/developer-docs#911 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100